//           pdf-new.cxx
//  Mon Mar 14 14:27:00 2011
//  Copyright  2011  Alcione Ferreira
//  <alcione.sombra@gmail.com>

#include <pdf-new.h>

/**
 * \param erro_no erro gerado pela biblioteca HARU
 * \param detalhe_no detalhamento do error
 * \param dados_usuario dados passados para a excessão
 */
void erro(HPDF_STATUS erro_no, HPDF_STATUS detalhe_no, void *dados_usuario)
	{
	printf ("ERROR: error_no=%04X, detail_no=%d\n", (unsigned int) erro_no, (int) detalhe_no);
  	throw exception();
	}

/**
 * \param tipo define o tipo de relatório que será gerado.
 * \param nargs informa a quantidade de dados que é passada na lista de variáveis.
 * \param ... várias informações do tipo va_list
 */
PDFNEW::PDFNEW(BANCOPG *conecao,int tipo, int nargs, ...)
	{
	va_list argumentos;

	va_start(argumentos,nargs);
	this->conexao = conecao;
	this->tipo_relatorio = tipo;
	this->retorno = 0;
	this->Arq_PDF.clear();
	this->Arq_PDF = "Relatorio";
	this->datas[0].clear();
	this->datas[0] = data_formatada(va_arg(argumentos,char *),1);
	this->Arq_PDF += "-"+ this->datas[0];
	this->datas[1].clear();
	this->datas[1] = data_formatada(va_arg(argumentos,char *),1);
	this->Arq_PDF += "-"+this->datas[1].substr(8,2);
	this->cod_fun = va_arg(argumentos,int);
	this->dados_funcionario (1);
	//cout << this->tipo_relatorio << endl;
	switch(this->tipo_relatorio)
		{
		case 1:
			{
			if (nargs == 4)
				{
				this->cod_servico.clear();
				this->cod_servico = va_arg(argumentos,char *);
				cout << this->cod_servico << endl;
				this->dados_servico ();
				this->Arq_PDF += "-"+ this->cod_servico;
				}
			break;
			}
		case 2:
			{
			this->cod_funcionario.clear();
			this->cod_funcionario = va_arg(argumentos,char *);
			if (this->cod_funcionario.length() > 0)
				{
				this->dados_funcionario (2);
				this->Arq_PDF += "-"+ this->cod_funcionario;
				}
			if (nargs == 5)
				{
				this->cod_servico.clear();
				this->cod_servico = va_arg(argumentos,char *);
				this->dados_servico ();
				this->Arq_PDF += "-"+ this->cod_servico;
				}
			break;
			}
		case 3:
			{
			this->Arq_PDF += "-Credito";
			detalhe = va_arg(argumentos,int);
			break;
			}
		case 4:
			{
			this->Arq_PDF += "-Cliente";
			this->cod_cliente.clear();
			if (nargs == 5)
				{
				this->cod_cliente = va_arg(argumentos,char *);
				this->dados_cliente();
				this->Arq_PDF += "-"+this->cod_cliente;
				}
			detalhe = va_arg(argumentos,int);
			break;
			}
		case 14:
			{
			this->Arq_PDF += "-Cliente";
			this->cod_cliente.clear();
			if (nargs == 4)
				{
				this->cod_cliente = va_arg(argumentos,char *);
				this->dados_cliente();
				this->Arq_PDF += "-"+this->cod_cliente;
				}
			break;
			}
		case 5:
			{
			this->cod_funcionario.clear();
			this->cod_funcionario = va_arg(argumentos,char *);
			if (this->cod_funcionario.length() > 0)
				{
				this->dados_funcionario (2);
				this->Arq_PDF += "-"+ this->cod_funcionario;
				}
			this->dc_recibo.clear();
			this->dc_recibo = va_arg(argumentos,char *);
			this->Arq_PDF += "-"+ this->dc_recibo;
			break;
			}
		case 6:
			{
			this->Arq_PDF += "-ResumoEntrada";
			break;
			}
		case 7:
			{
			this->Arq_PDF += "-ResumoSaida";
			break;
			}
		case 8:
			{
			this->cod_funcionario.clear();
			this->cod_funcionario = va_arg(argumentos,char *);
			if (this->cod_funcionario.length() > 0)
				{
				this->dados_funcionario (2);
				this->Arq_PDF += "-"+ this->cod_funcionario;
				}
			this->Arq_PDF += "-Recibos";
			break;
			}
		case 9:
			{
			this->Arq_PDF += "-RecibosDebito";
			break;
			}
		case 10:
			{
			this->cod_funcionario.clear();
			this->cod_funcionario = va_arg(argumentos,char *);
			this->dados_funcionario (2);
			this->Arq_PDF += "-"+ this->cod_funcionario;
			break;
			}
		case 11:
		case 12:
			{
			this->Arq_PDF += "-Selos";
			break;
			}
		case 13:
			{
			this->Arq_PDF += "-Escrituras";
			break;
			}
		}
	va_end(argumentos);
	this->Arq_PDF.append(".pdf");
	this->PDF_doc = HPDF_New(erro,NULL);
	if (!this->PDF_doc)
		{
		cout << "Erro: não foi possível criar o objeto PDF." << endl;
		this->retorno = 1;
		}
	//HPDF_SetPassword(PDF_doc,"4lc10n3","sombra");
	HPDF_SetInfoAttr(this->PDF_doc,HPDF_INFO_AUTHOR,"Alcione Ferreira");
	HPDF_SetInfoAttr(this->PDF_doc,HPDF_INFO_CREATOR,"Alcione Ferreira");
	HPDF_SetInfoAttr(this->PDF_doc,HPDF_INFO_TITLE,"Relatorio Sitema do Caixa");
	HPDF_SetPageMode(this->PDF_doc,HPDF_PAGE_MODE_USE_OUTLINE);
	this->texto();
	}

/**
 * Destrutor da classe.
 */
PDFNEW::~PDFNEW()
	{
  	this->processar();
	if (this->retorno)
		{
		cout << "erro" << endl;
		}
	HPDF_Free(this->PDF_doc);
	}

/**
 * Se não ocorrer erros na montagem do arquivo ele será salvo caso contrário
 * cairá na excessão.
 */
void PDFNEW::processar()
	{
	string CMD;
	char *comando;
	try
		{
	  	HPDF_SaveToFile(this->PDF_doc,this->Arq_PDF.c_str());
		CMD.clear();
		#if !defined(NO_LINUX)
		CMD = "/usr/bin/gnome-open "+this->Arq_PDF;
		comando = new char[CMD.length()+1];
		strcpy(comando,CMD.c_str());
		system (comando);
		delete comando;
		#else
		ShellExecute(0, "open", this->Arq_PDF.c_str(), NULL, NULL, SW_SHOWDEFAULT);
		#endif
		this->retorno = 0;
    	}
	catch(exception &resultado)
		{
		cout << resultado.what() << endl;
		this->retorno = 1;
		}
	}

/**
 * Cria um cabeçalho padrão para o arquivo pdf.
 */
void PDFNEW::set_cabecalho()
	{
	string TEXTO, AUX;
	char *texto, *aux;
	int len, c;

	this->dst = HPDF_Page_CreateDestination (this->Pagina);
  	HPDF_Destination_SetXYZ (this->dst, 0, this->Altura, 1);
  	HPDF_SetOpenAction(this->PDF_doc, this->dst);
	
	this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Helvetica", "WinAnsiEncoding");
  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 10);

	HPDF_Page_BeginText (this->Pagina);
	switch(this->tipo_relatorio)
		{
		case 1:
		case 2:
			{
			TEXTO.clear();
			TEXTO = "Relatório por Serviços no período de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			if (this->cod_servico.length() != 0)
				{
				TEXTO += " - Serviço: "+this->codigo_servico + " - "+this->desc_servico;
				}
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 3:
			{
			TEXTO.clear();
			TEXTO = "Relatório de Créditos de : ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 4:
			{
			TEXTO.clear();
			TEXTO = "Relatório de Créditos por Cliente";
			if (this->cod_cliente.length() > 0)
				{
				TEXTO += ":"+this->nome_cliente;
				}
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 5:
			{
			TEXTO.clear();
			TEXTO = "Recibos por Funcionário de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			if (this->cod_funcionario.length() > 0)
				{
				TEXTO += " Funcionário: "+this->nome_funcionario;
				}
			TEXTO += " Tipo: ";
			if(this->dc_recibo.compare("C") == 0)
				{
				TEXTO.append("Crédito");
				}
			else
				{
				TEXTO.append("Débito");
				}
			delete aux;
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 6:
			{
			TEXTO.clear();
			TEXTO = "Resumo das Entradas do Caixa de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 7:
			{
			TEXTO.clear();
			TEXTO = "Resumo das Saídas do Caixa de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 8:
			{
			TEXTO.clear();
			TEXTO = "Recibos de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 9:
			{
			TEXTO.clear();
			TEXTO = "Recibos de Débito: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 10:
			{
			TEXTO.clear();
			TEXTO = "Resumo Serviços/Selos de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			if (this->cod_funcionario.length() > 0)
				{
				TEXTO += " Funcionário: "+this->nome_funcionario;
				}
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 11:
		case 12:
			{
			TEXTO.clear();
			TEXTO = "Resumo Serviços/Selos de: ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			TEXTO += " Geral";
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 13:
			{
			TEXTO.clear();
			TEXTO = "Escrituras - Extrato de FUNJECC de ";
			aux = new char[this->datas[0].length()+1];
			strcpy(aux,this->datas[0].c_str());
			TEXTO.append(data_formatada(aux,2));
			delete aux;
			TEXTO += " à ";
			aux = new char[this->datas[1].length()+1];
			strcpy(aux,this->datas[1].c_str());
			TEXTO.append(data_formatada(aux,2));
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		case 14:
			{
			TEXTO.clear();
			TEXTO = "Relatório de SUBISSQN por Cliente";
			if (this->cod_cliente.length() > 0)
				{
				TEXTO += ":"+this->nome_cliente;
				}
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
  			HPDF_Page_TextOut (this->Pagina, 15, this->Altura-40, converter(texto,1));
			delete texto;
			break;
			}
		}
	HPDF_Page_EndText (this->Pagina);
	HPDF_Page_MoveTo (this->Pagina, 15, this->Altura - 50);
  	HPDF_Page_LineTo (this->Pagina, this->Largura - 20, this->Altura - 50);
  	HPDF_Page_Stroke (this->Pagina);
	//Retângulo de teste
	/*this->rect.left = 15;
  	this->rect.top = 786;
  	this->rect.right = 575;
  	this->rect.bottom = 771;
	cout << this->rect.left << endl;
	cout << this->rect.bottom << endl;
	cout << this->rect.right - this->rect.left << endl;
	cout << this->rect.top - this->rect.bottom << endl;
	//                                   15                  741                    560                                  45
	HPDF_Page_Rectangle (this->Pagina, this->rect.left, this->rect.bottom, this->rect.right - this->rect.left, this->rect.top - this->rect.bottom);
  	HPDF_Page_Stroke (this->Pagina);*/
	switch(this->tipo_relatorio)
		{
		case 1:
		case 2:
			{
			this->colunas = 7;
			c = 0;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			if (this->tipo_relatorio == 2)
				{
				this->colunas = 8;
				AUX.clear();
				AUX = "CF";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->coluna[c][0] = 15;
				this->coluna[c][1] = 30;
				c++;
  				HPDF_Page_TextRect (this->Pagina,15, 786, 30, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  				HPDF_Page_EndText (this->Pagina);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				AUX.clear();
				AUX = "Nº REC";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->coluna[c][0] = 30;
				this->coluna[c][1] = 70;
				c++;
  				HPDF_Page_TextRect (this->Pagina,30, 786, 70, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  				HPDF_Page_EndText (this->Pagina);
				}
			else
				{
				AUX.clear();
				AUX = "Nº REC";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->coluna[c][0] = 15;
				this->coluna[c][1] = 70;
				c++;
  				HPDF_Page_TextRect (this->Pagina,15, 786, 70, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  				HPDF_Page_EndText (this->Pagina);
				}
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "DATA";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[c][0] = 70;
			this->coluna[c][1] = 135;
			c++;
  			HPDF_Page_TextRect (this->Pagina,70, 786, 135, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "QTD.";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[c][0] = 135;
			this->coluna[c][1] = 170;
			c++;
  			HPDF_Page_TextRect (this->Pagina,135, 786, 170, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "TOTAL LIQ.";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[c][0] = 170;
			this->coluna[c][1] = 235;
			c++;
  			HPDF_Page_TextRect (this->Pagina,170, 786, 235, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "STATUS";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[c][0] = 235;
			this->coluna[c][1] = 285;
			c++;
  			HPDF_Page_TextRect (this->Pagina,235, 786, 285, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "CRED/DEB";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[c][0] = 285;
			this->coluna[c][1] = 355;
			c++;
  			HPDF_Page_TextRect (this->Pagina,285, 786, 355, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "NOME";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[c][0] = 355;
			this->coluna[c][1] = this->Largura-20;
			c++;
  			HPDF_Page_TextRect (this->Pagina,355, 786, this->Largura-20, 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 3:
			{
			this->colunas=5;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Data Emissão";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 85;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Cliente";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 85;
			this->coluna[1][1] = 355;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nº REC";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 355;
			this->coluna[2][1] = 410;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "TOTAL";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 410;
			this->coluna[3][1] = 470;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "FUNCIONÁRIO";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 470;
			this->coluna[4][1] = this->Largura-20;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 4:
			{
			this->colunas=6;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Cliente";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 285;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "QTD";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 285;
			this->coluna[1][1] = 320;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "VALOR";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 320;
			this->coluna[2][1] = 380;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nº REC";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 380;
			this->coluna[3][1] = 435;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Data Emissão";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 435;
			this->coluna[4][1] = 505;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Valor Total";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[5][0] = 505;
			this->coluna[5][1] = this->Largura-20;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], 786, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 5:
			{
			this->colunas = 5;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nº REC";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 70;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Data Emissão";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 70;
			this->coluna[1][1] = 140;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nome Cliente";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 140;
			this->coluna[2][1] = 410;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "VALOR";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 410;
			this->coluna[3][1] = 470;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Situação";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 470;
			this->coluna[4][1] = this->Largura-20;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 6:
			{
			this->colunas = 5;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Cód. Serv";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 70;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Descrição";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 70;
			this->coluna[1][1] = 340;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "QTD. Total";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 340;
			this->coluna[2][1] = 400;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "SubTotal";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 400;
			this->coluna[3][1] = 470;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Desconto";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 470;
			this->coluna[4][1] = this->Largura-20;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 7:
			{
			this->colunas = 4;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Cód. Serv";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 70;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Histórico";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 70;
			this->coluna[1][1] = 400;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "SubTotal";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 400;
			this->coluna[2][1] = 470;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Número";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 470;
			this->coluna[3][1] = this->Largura-20;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 8:
			{
			this->colunas = 8;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nº Rec";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 70;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Data Emissão";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 70;
			this->coluna[1][1] = 140;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nome Cliente";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 140;
			this->coluna[2][1] = 310;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Protocolo";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 310;
			this->coluna[3][1] = 385;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "TOTAL";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 385;
			this->coluna[4][1] = 455;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "D/C";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[5][0] = 455;
			this->coluna[5][1] = 473;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], 786, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Func.";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[6][0] = 473;
			this->coluna[6][1] = 540;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], 786, this->coluna[6][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Status";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[7][0] = 540;
			this->coluna[7][1] = this->Largura-10;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[7][0], 786, this->coluna[7][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 9:
			{
			this->colunas = 9;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nº Rec";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 70;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Data Emissão";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 70;
			this->coluna[1][1] = 140;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Data Quit.";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 140;
			this->coluna[2][1] = 210;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Nome Cliente";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 210;
			this->coluna[3][1] = 320;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Protocolo";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 320;
			this->coluna[4][1] = 385;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "TOTAL";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[5][0] = 385;
			this->coluna[5][1] = 455;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], 786, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "D/C";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[6][0] = 455;
			this->coluna[6][1] = 473;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], 786, this->coluna[6][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Func.";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[7][0] = 473;
			this->coluna[7][1] = 540;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[7][0], 786, this->coluna[7][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Status";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[8][0] = 540;
			this->coluna[8][1] = this->Largura-10;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[8][0], 786, this->coluna[8][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 10:
		case 11:
		case 12:
			{
			this->colunas = 3;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "Serviço";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 225;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "QTD Caixa";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 225;
			this->coluna[1][1] = 285;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "QTD Selos";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 285;
			this->coluna[2][1] = 345;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 13:
			{
			this->colunas = 11;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "DATA";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 15;
			this->coluna[0][1] = 70;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 10);
			AUX.clear();
			AUX = "TIPO";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 70;
			this->coluna[1][1] = 100;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "LIVRO";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 100;
			this->coluna[2][1] = 135;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "FOLHAS";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 135;
			this->coluna[3][1] = 187;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "BASE DE CÁLCULO";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 185;
			this->coluna[4][1] = 285;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "EMOL";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[5][0] = 295;
			this->coluna[5][1] = 345;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], 786, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "FJ 10";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[6][0] = 345;
			this->coluna[6][1] = 385;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], 786, this->coluna[6][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "FJ 3";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[7][0] = 385;
			this->coluna[7][1] = 425;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[7][0], 786, this->coluna[7][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "ISS";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[8][0] = 425;
			this->coluna[8][1] = 465;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[8][0], 786, this->coluna[8][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "FPE";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[9][0] = 465;
			this->coluna[9][1] = 505;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[9][0], 786, this->coluna[9][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			//HPDF_Page_SetTextLeading (this->Pagina, 12);
			AUX.clear();
			AUX = "TOTAL";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[10][0] = 505;
			this->coluna[10][1] = this->Largura-20;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[10][0], 786, this->coluna[10][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			break;
			}
		case 14:
			{
			this->colunas = 6;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "Data";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[0][0] = 20;
			this->coluna[0][1] = 90;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], 786, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "Recibo";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[1][0] = 90;
			this->coluna[1][1] = 160;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], 786, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "Total";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[2][0] = 160;
			this->coluna[2][1] = 230;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], 786, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "Total Liq.";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[3][0] = 230;
			this->coluna[3][1] = 300;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], 786, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "B. ISSQN";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[4][0] = 300;
			this->coluna[4][1] = 370;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], 786, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 8);
			AUX.clear();
			AUX = "ISSQN";
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->coluna[5][0] = 370;
			this->coluna[5][1] = 440;
  			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], 786, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
  			HPDF_Page_EndText (this->Pagina);
			delete aux;
			break;
			}
		}
	//Retângulo de teste
	HPDF_Page_MoveTo (this->Pagina, 15, this->Altura - 70);
  	HPDF_Page_LineTo (this->Pagina, this->Largura - 20, this->Altura - 70);
  	HPDF_Page_Stroke (this->Pagina);
	}

/**
 * Cria um rodapé padrão para o arquivo pdf.
 */
void PDFNEW::set_rodape()
	{
	char *texto, *aux;
	string TEXTO, AUX;
	int deslocamento;

	HPDF_Page_MoveTo (this->Pagina, 15, 40);
  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, 40);
  	HPDF_Page_Stroke (this->Pagina);

	this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Helvetica", "WinAnsiEncoding");
  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 8);

	HPDF_Page_BeginText (this->Pagina);
	switch(this->tipo_relatorio)
		{
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
		case 11:
		case 12:
		case 13:
		case 14:
			{
			TEXTO.clear();
			TEXTO = "Código: ";
			aux = new char[4];
			sprintf(aux,"%d",this->cod_fun);
			TEXTO.append(aux);
			TEXTO += " - "+this->nome_fun;				
			texto = new char[TEXTO.length()+1];
			strcpy(texto,TEXTO.c_str());
			HPDF_Page_TextOut (this->Pagina, 15, 30, converter(texto,1));
			delete texto;
			break;
			}
		}
	TEXTO.clear();
	TEXTO = "Página ";
	aux = new char[4];
	sprintf(aux,"%d",this->pag);
	TEXTO.append(aux);
	delete aux;
	TEXTO += " de ";
	aux = new char[4];
	sprintf(aux,"%d",this->pags);
	TEXTO.append(aux);
	delete aux;
	texto = new char[TEXTO.length()+1];
	strcpy(texto,TEXTO.c_str());
	deslocamento = strlen(texto);
	deslocamento *= 3.5;
	HPDF_Page_TextOut (this->Pagina, (this->Largura-20)-deslocamento, 30, converter(texto,1));
	delete texto;
	HPDF_Page_EndText (this->Pagina);
	}

/**
 * Usado para gerar o conteúdo dos relatórios
 */
void PDFNEW::texto()
	{
	string texto, serv, SQL, AUX;
	char *aux_tex, *sql, *aux;
	int it,i,j,r,x,rg,len,ajuste,cx;
	double valor, total;
	bool servico, funcionario;
	vector<vector<string> >::iterator irg;
	vector<string> linha;

	servico = false;
	funcionario = false;
	ajuste = 0;
	switch(this->tipo_relatorio)
		{
		case 1:
		case 2:
			{
			SQL.clear();
			SQL = "select lancamentos.rec, lancamentos.data, servicos.codigo, servicos.descricao, entrada.qtd, entrada.total, lancamentos.status, lancamentos.tipo, clientes.nome";
			if (this->tipo_relatorio == 2)
				{
				SQL += ", lancamentos.cod_fun";
				}
			SQL += ", servicos.cod_serv from";
			SQL += " caixa.lancamentos, caixa.entrada, cadastro.clientes, cadastro.servicos where ";
			SQL += " lancamentos.rec=entrada.rec and lancamentos.data=entrada.data and lancamentos.cod_cli=clientes.cod_cli and entrada.cod_serv=servicos.cod_serv and ";
			SQL += " lancamentos.e_s=1";
			if (this->tipo_relatorio == 1)
				{
				SQL += " and lancamentos.cod_fun=";
				aux = new char[4];
				sprintf(aux,"%d",this->cod_fun);
				SQL.append(aux);
				delete aux;
				}
			if (this->tipo_relatorio == 2)
				{
				if (this->cod_funcionario.length() > 0)
					{
					SQL += "and lancamentos.cod_fun=" + this->cod_funcionario;
					}
				}
			SQL += " and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' ";
			if (this->cod_servico.length() > 0)
				{
				SQL += " and servicos.cod_serv="+this->cod_servico+" ";
				}
			SQL += "order by servicos.codigo, lancamentos.rec";
			if (this->tipo_relatorio == 1)
				{
				this->col_reg[0]=0;
				this->col_reg[1]=1;
				this->col_reg[2]=4;
				this->col_reg[3]=5;
				this->col_reg[4]=6;
				this->col_reg[5]=7;
				this->col_reg[6]=8;
				}
			if (this->tipo_relatorio == 2)
				{
				this->col_reg[0]=9;
				this->col_reg[1]=0;
				this->col_reg[2]=1;
				this->col_reg[3]=4;
				this->col_reg[4]=5;
				this->col_reg[5]=6;
				this->col_reg[6]=7;
				this->col_reg[7]=8;
				}
			//cout << SQL << endl;
			break;
			}
		case 3:
			{
			SQL.clear();
			SQL = "select lancamentos.data, clientes.nome, lancamentos.rec, lancamentos.total, funcionario.u_login ";
			SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun ";
			SQL += "where lancamentos.tipo='C' and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' and lancamentos.status order by lancamentos.data asc";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			break;
			}
		case 4:
			{
			SQL.clear();
			SQL = "select count(*) from caixa.lancamentos inner join caixa.entrada on lancamentos.e_s=entrada.e_s and lancamentos.rec=entrada.rec and lancamentos.data=entrada.data where lancamentos.tipo='C' and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' and lancamentos.status ";
			if (this->cod_cliente.length() > 0)
				{
				SQL += " and lancamentos.cod_cli="+this->cod_cliente;
				}
			//cout << SQL << endl;
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			this->conexao->executar(sql);
			delete sql;
			if (this->conexao->query_result == 3)
				{
				cout << this->conexao->mensagem << endl;
				}
			else
				{
				//cout << this->conexao->resultado(0,0) << endl;
				ajuste = atoi(this->conexao->resultado(0,0));
				//cout << ajuste;
				}
			SQL.clear();
			SQL = "select clientes.nome, lancamentos.rec, lancamentos.data, lancamentos.total from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli where lancamentos.e_s=1 and lancamentos.tipo='C' and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' and lancamentos.status ";
			if (this->cod_cliente.length() > 0)
				{
				SQL += " and lancamentos.cod_cli=" + this->cod_cliente;
				}
			//cout << SQL << endl;
			this->col_reg[0]=0;
			this->col_reg[1]=-1;
			this->col_reg[2]=-1;
			this->col_reg[3]=1;
			this->col_reg[4]=2;
			this->col_reg[5]=3;
			break;			
			}
		case 5:
			{
			SQL.clear();
			SQL = "select lancamentos.rec, lancamentos.data, clientes.nome, lancamentos.total, lancamentos.status, funcionario.cod_fun, funcionario.nome ";
			SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun ";
			SQL += "where lancamentos.status and lancamentos.tipo='"+this->dc_recibo+"' and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"'";
			if (this->cod_funcionario.length() > 0)
				{
				SQL += " and lancamentos.cod_fun="+this->cod_funcionario+" order by lancamentos.data, lancamentos.rec";
				}
			else
				{
				SQL += " order by funcionario.nome, lancamentos.data , lancamentos.rec ";
				}
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			break;
			}
		case 6:
			{
			SQL.clear();
			SQL = "select servicos.codigo, servicos.descricao, sum(entrada.qtd), sum(entrada.total-(entrada.funjecc10+entrada.issqn)), sum(entrada.desconto) ";
			SQL += "from caixa.lancamentos inner join caixa.entrada on lancamentos.rec=entrada.rec and lancamentos.data=entrada.data inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv ";
			SQL += "where lancamentos.data_qt >= '"+this->datas[0]+"' and lancamentos.data_qt <= '"+this->datas[1]+"' ";
			SQL += "group by servicos.codigo, servicos.descricao order by servicos.codigo";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			break;
			}
		case 7:
			{
			SQL.clear();
			SQL = "select servicos.codigo, servicos.descricao, saida.historico_complementar, saida.valor, saida.rec, clientes.nome ";
			SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join caixa.saida on lancamentos.rec=saida.rec and lancamentos.data=saida.data inner join cadastro.servicos on saida.cod_serv=servicos.cod_serv ";
			SQL += "where lancamentos.status and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' and lancamentos.e_s=2 ";
			SQL += "order by lancamentos.rec";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=3;
			this->col_reg[3]=4;
			break;
			}
		case 8:
			{
			SQL.clear();
			SQL = "select lancamentos.rec, lancamentos.data, clientes.nome, lancamentos.protocolo, lancamentos.total, lancamentos.tipo, funcionario.u_login, lancamentos.status ";
			SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun ";
			SQL += "where lancamentos.e_s=1 and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' ";
			if (this->cod_funcionario.length() > 0)
				{
				SQL += " and lancamentos.cod_fun="+this->cod_funcionario+" ";
				}
			SQL += "order by lancamentos.data ,lancamentos.rec";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			this->col_reg[5]=5;
			this->col_reg[6]=6;
			this->col_reg[7]=7;
			break;
			}
		case 9:
			{
			SQL.clear();
			SQL = "select lancamentos.rec, lancamentos.data, lancamentos.data_qt, clientes.nome, lancamentos.protocolo, lancamentos.total, lancamentos.tipo, funcionario.u_login, lancamentos.status ";
			SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun ";
			SQL += "where lancamentos.e_s=1 and lancamentos.tipo='D' and lancamentos.data_qt >= '"+this->datas[0]+"' and lancamentos.data_qt <= '"+this->datas[1]+"' and lancamentos.status ";
			SQL += "order by lancamentos.data ,lancamentos.rec";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			this->col_reg[5]=5;
			this->col_reg[6]=6;
			this->col_reg[7]=7;
			this->col_reg[8]=8;
			break;
			}
		case 10:
			{
			SQL.clear();
			SQL = "select servicos.descricao, sum(entrada.qtd), servicos.cod_serv from caixa.lancamentos inner join caixa.entrada on lancamentos.rec=entrada.rec and lancamentos.data=entrada.data inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv where ";
			SQL += " lancamentos.cod_fun="+this->cod_funcionario+" and entrada.data >= '"+this->datas[0]+"' and entrada.data <= '"+this->datas[1]+"' and lancamentos.status ";
			SQL += " group by servicos.cod_serv, servicos.descricao order by servicos.descricao ";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			break;
			}
		case 11:
			{
			SQL.clear();
			SQL = "select servicos.descricao, sum(entrada.qtd), servicos.cod_serv from caixa.lancamentos inner join caixa.entrada on lancamentos.rec=entrada.rec and lancamentos.data=entrada.data inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv where ";
			SQL += " entrada.data >= '"+this->datas[0]+"' and entrada.data <= '"+this->datas[1]+"' and lancamentos.status and lancamentos.e_s=1 ";
			SQL += " group by servicos.cod_serv, servicos.descricao order by servicos.descricao ";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			break;
			}
		case 12:
			{
			SQL.clear();
			SQL = "select servicos.descricao, sum(entrada.qtd), servicos.cod_serv, funcionario.nome from caixa.lancamentos inner join caixa.entrada on lancamentos.rec=entrada.rec and lancamentos.data=entrada.data inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun where ";
			SQL += " entrada.data >= '"+this->datas[0]+"' and entrada.data <= '"+this->datas[1]+"' and lancamentos.status ";
			SQL += " group by servicos.cod_serv, servicos.descricao, funcionario.nome order by funcionario.nome,servicos.descricao ";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			break;
			}
		case 13:
			{
			SQL.clear();
			SQL = "select count(cod_serv) from cadastro.servicos";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			this->col_reg[5]=5;
			this->col_reg[6]=6;
			this->col_reg[7]=7;
			this->col_reg[8]=8;
			this->col_reg[9]=9;
			this->col_reg[10]=10;
			this->tipo_relatorio = 13;
			break;
			}
		case 14:
			{
			SQL.clear();
			SQL = "select data, rec, total, total_liq, s_issqn, (s_issqn*0.05) as issqn from caixa.lancamentos where ";
			SQL += "data_qt >= '"+this->datas[0]+"' and data_qt <= '"+this->datas[1]+"' and lancamentos.status and cod_cli="+ this->cod_cliente;
			SQL += " order by data, rec";
			this->col_reg[0]=0;
			this->col_reg[1]=1;
			this->col_reg[2]=2;
			this->col_reg[3]=3;
			this->col_reg[4]=4;
			this->col_reg[5]=5;
			this->tipo_relatorio = 14;
			break;
			}
		}
	sql = new char [SQL.length()+1];
	strcpy(sql,SQL.c_str());
	this->conexao->executar(sql);
	delete sql;
	if (this->conexao->query_result == 3)
		{
		cout << this->conexao->mensagem << endl;
		}
	else
		{
		this->total_reg = this->conexao->registros;
		if (this->tipo_relatorio == 4)
			{
			this->pags = (3*this->total_reg+ajuste)/48;
			if ((this->pags == 0) && (this->total_reg > 0))
			    {
				this->pags++;
				}
			}
		else
			{
			this->pags = (this->total_reg+ajuste)/48;
			this->pags++;
			}
		this->conexao->resultado();
		rg = 0;
		if (this->total_reg > 0)
			{
			irg = this->conexao->resultados.begin();
			linha = *irg;
			}
		total = 0;
		for (i=0; i < this->pags;i++)
			{
			x = 765;
			this->pag = i+1;
			//cout << this->pag << " de " << this->pags << endl;
			this->Pagina = HPDF_AddPage (this->PDF_doc);
			HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

		  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
		  	this->Largura = HPDF_Page_GetWidth (this->Pagina);
			this->set_cabecalho();
			//Setando fonte padrão
			this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
		  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
			if (this->total_reg > 0)
				{
				
				for (r=0; r < 48; r++)
					{
					switch(this->tipo_relatorio)
						{
						case 1:
						case 2:
							{
							if (!(this->cod_servico.length() > 0))
								{
								if (servico)
									{
									if (serv.compare(linha.at(2)) == 0)
										{
										servico = false;
										}
									}
								if (!servico)
									{
									servico = true;
									serv.clear();
									serv = linha.at(2);
									texto.clear();
									texto = "Código Servico: "+serv+" - ";
									texto += linha.at(3);
									texto += " Ocorrências: " + contagem(serv);
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									HPDF_Page_BeginText (this->Pagina);
									aux = new char[texto.length()+1];
									strcpy(aux,texto.c_str());
									HPDF_Page_TextOut (this->Pagina, 15, x-10, converter(aux,1));
									delete aux;
									HPDF_Page_EndText (this->Pagina);
									x -= 15;
									r++;
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									}
								}
							else
								{
								if (rg == 0)
									{
									serv.clear();
									serv = linha.at(2);
									texto.clear();
									texto += " Ocorrências: " + contagem(serv);
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									HPDF_Page_BeginText (this->Pagina);
									aux = new char[texto.length()+1];
									strcpy(aux,texto.c_str());
									HPDF_Page_TextOut (this->Pagina, 15, x-10, converter(aux,1));
									delete aux;
									HPDF_Page_EndText (this->Pagina);
									x -= 15;
									r++;
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									}
								}
							for (j=0; j < this->colunas; j++)
								{
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								if (this->tipo_relatorio == 1)
									{
									switch(j)
										{
										case 1:
											{
											aux = data_formatada(aux,2);
											break;
											}
										case 2:
											{
											AUX.clear();
											AUX = casa_milhar(aux,1);
											delete aux;
											aux = new char[AUX.length()+1];
											strcpy(aux,AUX.c_str());
											break;
											}
										case 3:
											{
											AUX.clear();
											AUX.append(aux);
											delete aux;
											it = AUX.find(".");
											if (it != string::npos)	
												{
												AUX.replace(it,1,",");
												}
											valor = atof(AUX.c_str());
											total += 0;
											if (!linha.at(this->col_reg[4]).compare("t"))
												{
												total += valor;
												}
											aux = new char[32];
											sprintf(aux,"%.03f",valor);
											aux[strlen(aux)-1] = '\0';
											cout << __FILE__ << ": " << __LINE__ << endl;
											AUX.clear();
											AUX = casa_milhar(aux,0);
											delete aux;
											aux = new char[AUX.length()+1];
											strcpy(aux,AUX.c_str());
											break;
											}
										case 4:
											{
											AUX.clear();
											AUX.append(aux);
											delete aux;
											aux = new char[16];
											strcpy(aux,"CAN");
											if (!AUX.compare("t"))
												{
												strcpy(aux,"OK");
												}
											break;
											}
										case 6:
											{
											len = strlen(aux);
											if (len > 28)
												{
												aux[28] = '\0';
												}
											break;
											}
										}
									if (j == 3)
										{
						  				HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
										}
									else if (j == 6)
										{
										HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
										}
									else
										{
										HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
										}
									}
								else
									{
									switch(j)
										{
										case 2:
											{
											aux = data_formatada(aux,2);
											break;
											}
										case 3:
											{
											AUX.clear();
											AUX = casa_milhar(aux,1);
											delete aux;
											aux = new char[AUX.length()+1];
											strcpy(aux,AUX.c_str());
											break;
											}
										case 4:
											{
											AUX.clear();
											AUX.append(aux);
											delete aux;
											it = AUX.find(".");
											if (it != string::npos)	
												{
												AUX.replace(it,1,",");
												}
											valor = atof(AUX.c_str());
											total += 0;
											if (!linha.at(this->col_reg[5]).compare("t"))
												{
												total += valor;
												}
											aux = new char[32];
											sprintf(aux,"%.03f",valor);
											aux[strlen(aux)-1] = '\0';
											cout << __FILE__ << ": " << __LINE__ << endl;
											AUX.clear();
											AUX = casa_milhar(aux,0);
											delete aux;
											aux = new char[AUX.length()+1];
											strcpy(aux,AUX.c_str());
											break;
											}
										case 5:
											{
											AUX.clear();
											AUX.append(aux);
											delete aux;
											aux = new char[16];
											strcpy(aux,"CAN");
											if (!AUX.compare("t"))
												{
												strcpy(aux,"OK");
												}
											break;
											}
										case 7:
											{
											len = strlen(aux);
											if (len > 28)
												{
												aux[28] = '\0';
												}
											break;
											}
										}
									if (j == 4)
										{
						  				HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
										}
									else if (j == 7)
										{
										HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
										}
									else
										{
										HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
										}
									}
					  			HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						case 3:
							{
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 0:
										{
										aux = data_formatada(aux,2);
										break;
										}
									case 1:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										break;
										}
									case 3:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)	
											{
											AUX.replace(it,1,",");
											}
										valor = atof(AUX.c_str());
										total += valor;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						case 4:
							{
							if (r >= 48)
								{
								this->set_rodape ();
								x = 765;
								cout << this->pag << endl;
								this->pag++;
								cout << this->pag << endl;
								this->Pagina = HPDF_AddPage (this->PDF_doc);
								HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

							  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
							  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

								this->set_cabecalho();
								//Setando fonte padrão
								this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
							  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
								r = 1;
								}
							for (j=0; j < this->colunas; j++)
								{
								if (this->col_reg[j] != -1)
									{
									cx = this->coluna[j][1];
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									this->Alinhamento = HPDF_TALIGN_CENTER;
									HPDF_Page_BeginText (this->Pagina);
									HPDF_Page_SetTextLeading (this->Pagina, 12);
									AUX.clear();
									//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
									AUX = linha.at(this->col_reg[j]);
									aux = new char[AUX.length()+1];
									strcpy(aux,AUX.c_str());
									switch(j)
										{
										case 0:
											{
											this->Alinhamento = HPDF_TALIGN_LEFT;
											len = strlen(aux);
											if (len > 35)
												{
												aux[35] = '\0';
												}
											cx += 20;
											break;
											}
										case 4:
											{
											aux = data_formatada(aux,2);
											break;
											}
										case 5:
											{
											this->Alinhamento = HPDF_TALIGN_RIGHT;
											AUX.clear();
											AUX.append(aux);
											delete aux;
											it = AUX.find(".");
											if (it != string::npos)
												{
												AUX.replace(it,1,",");
												}
											valor = char2double(AUX.c_str());
											total += valor;
											aux = new char[32];
											sprintf(aux,"%.03f",valor);
											aux[strlen(aux)-1] = '\0';
											cout << __FILE__ << ": " << __LINE__ << endl;
											AUX.clear();
											AUX = casa_milhar(aux,0);
											delete aux;
											aux = new char[AUX.length()+1];
											strcpy(aux,AUX.c_str());
											break;
											}
										}
									HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, cx, 15, converter(aux,1), this->Alinhamento, NULL);
									HPDF_Page_EndText (this->Pagina);
									delete aux;
									}
								}
							if (detalhe)
								{
								x -=15;
								r++;
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
				  				HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
								this->detalhamento(linha.at(1).c_str(),linha.at(2).c_str(),&r,&x);
								}
							if (r >= 47)
								{
								this->set_rodape ();
								x = 765;
								cout << this->pag << endl;
								this->pag++;
								cout << this->pag << endl;
								this->Pagina = HPDF_AddPage (this->PDF_doc);
								HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

							  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
							  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

								this->set_cabecalho();
								//Setando fonte padrão
								this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
							  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
								r = 1;
								}
							if (detalhe)
								{
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								}
							cout << "registro: " << r << endl;
							break;
							}
						case 5:
							{
							if (!(this->cod_funcionario.length() > 0))
								{
								if (funcionario)
									{
									if (serv.compare(linha.at(6)))
										{
										funcionario = false;
										}
									}
								if (!funcionario)
									{
									funcionario = true;
									serv.clear();
									serv = linha.at(6);
									texto.clear();
									texto = "Funcionário: "+serv+" - ";
									texto += linha.at(3);
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
									HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									HPDF_Page_BeginText (this->Pagina);
									aux = new char[texto.length()+1];
									strcpy(aux,texto.c_str());
									HPDF_Page_TextOut (this->Pagina, 15, x-10, converter(aux,1));
									delete aux;
									HPDF_Page_EndText (this->Pagina);
									x -= 15;
									r++;
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									}
								}
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 1:
										{
										aux = data_formatada(aux,2);
										break;
										}
									case 2:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										len = strlen(aux);
										if (len > 28)
											{
											aux[28] = '\0';
											}
										break;
										}
									case 3:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)
											{
											AUX.replace(it,1,",");
											}
										valor = atof(AUX.c_str());
										total += valor;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									case 4:
										{
										AUX.clear();
										AUX.append(aux);
										delete aux;
										aux = new char[16];
										strcpy(aux,"CAN");
										if (!AUX.compare("t"))
											{
											strcpy(aux,"OK");
											}
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						case 6:
							{
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 1:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										len = strlen(aux);
										if (len > 28)
											{
											aux[28] = '\0';
											}
										break;
										}
									case 2:
										{
										//cout << aux << endl;
										AUX.clear();
										AUX = casa_milhar(aux,1);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									case 3:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)	
											{
											AUX.replace(it,1,",");
											}
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										valor = atof(aux);
										total += valor;
										delete aux;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									case 4:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)	
											{
											AUX.replace(it,1,",");
											}
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										valor = atof(aux);
										total += valor;
										delete aux;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						case 7:
							{
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								if (j == 1)
									{
									AUX += " - ";
									AUX += linha.at(5);
									AUX += " - ";
									AUX += linha.at(2);
									}
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 1:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										len = strlen(aux);
										break;
										}
									case 2:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)
											{
											AUX.replace(it,1,",");
											}
										valor = atof(AUX.c_str());
										total += valor;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							//cout << r << endl;
							if (len > 48)
								{
								x -= 15;
								r++;
								}
							//cout << r << endl;
							if (r >= 47)
								{
								this->set_rodape ();
								x = 765;
								this->pag++;
								this->Pagina = HPDF_AddPage (this->PDF_doc);
								HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

							  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
							  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

								this->set_cabecalho();
								//Setando fonte padrão
								this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
							  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
								r = 0;
								}
							break;
							}
						case 8:
							{
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 1:
										{
										aux = data_formatada(aux,2);
										break;
										}
									case 2:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										len = strlen(aux);
										if (len > 20)
											{
											aux[20] = '\0';
											}
										break;
										}
									case 4:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)
											{
											AUX.replace (it,1,",");
											}
										valor = atof(AUX.c_str());
										total += valor;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									case 6:
										{
										len = strlen(aux);
										if (len > 8)
											{
											aux[8] = '\0';
											}
										this->Alinhamento = HPDF_TALIGN_LEFT;
										break;
										}
									case 7:
										{
										AUX.clear();
										AUX.append(aux);
										delete aux;
										aux = new char[16];
										strcpy(aux,"CAN");
										if (!AUX.compare("t"))
											{
											strcpy(aux,"OK");
											}
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}										
						case 9:
							{
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << " j: " << j << endl;
								AUX = linha.at(j);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 1:
									case 2:
										{
										aux = data_formatada(aux,2);
										break;
										}
									case 3:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										len = strlen(aux);
										if (len > 12)
											{
											aux[12] = '\0';
											}
										break;
										}
									case 5:
										{
										//cout << aux << endl;
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)
											{
											AUX.replace(it,1,",");
											}
										valor = atof(AUX.c_str());
										total += valor;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									case 7:
										{
										len = strlen(aux);
										if (len > 8)
											{
											aux[8] = '\0';
											}
										this->Alinhamento = HPDF_TALIGN_LEFT;
										break;
										}
									case 8:
										{
										AUX.clear();
										AUX.append(aux);
										delete aux;
										aux = new char[16];
										strcpy(aux,"CAN");
										if (!AUX.compare("t"))
											{
											strcpy(aux,"OK");
											}
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						case 10:
						case 11:
						case 12:
							{
							if (this->tipo_relatorio == 12)
								{
								if (funcionario)
									{
									if (serv.compare(linha.at(3)))
										{
										funcionario = false;
										this->set_rodape ();
										x = 765;
										this->pag++;
										this->Pagina = HPDF_AddPage (this->PDF_doc);
										HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

									  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
									  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

										this->set_cabecalho();
										//Setando fonte padrão
										this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
									  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
										}
									}
								if (!funcionario)
									{
									funcionario = true;
									serv.clear();
									serv = linha.at(3);
									texto.clear();
									texto = "Funcionário: "+serv;
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
									HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									HPDF_Page_BeginText (this->Pagina);
									aux = new char[texto.length()+1];
									strcpy(aux,texto.c_str());
									HPDF_Page_TextOut (this->Pagina, 15, x-10, converter(aux,1));
									delete aux;
									HPDF_Page_EndText (this->Pagina);
									x -= 15;
									r++;
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  						HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									}
								}
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << " j: " << j << endl;
								AUX = linha.at(j);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 0:
										{
										this->Alinhamento = HPDF_TALIGN_LEFT;
										break;
										}
									case 2:
										{
										sprintf(aux,"%d",this->contar_selos(atoi(aux)));
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						case 13:
							{
							this->Alinhamento = HPDF_TALIGN_CENTER;
							//HPDF_Page_BeginText (this->Pagina);
							//HPDF_Page_SetTextLeading (this->Pagina, 10);
							this->relatorio_escr (&r,&x);
							break;
							}
						case 14:
							{
							for (j=0; j < this->colunas; j++)
								{
								this->Alinhamento = HPDF_TALIGN_CENTER;
								HPDF_Page_BeginText (this->Pagina);
								HPDF_Page_SetTextLeading (this->Pagina, 12);
								AUX.clear();
								//cout << "linha: " << rg << " coluna: "<< this->col_reg[j] << endl;
								AUX = linha.at(this->col_reg[j]);
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								switch(j)
									{
									case 0:
										{
										aux = data_formatada(aux,2);
										break;
										}
									case 2:
									case 3:
									case 4:
									case 5:
										{
										this->Alinhamento = HPDF_TALIGN_RIGHT;
										AUX.clear();
										AUX.append(aux);
										delete aux;
										it = AUX.find(".");
										if (it != string::npos)
											{
											AUX.replace(it,1,",");
											}
										valor = atof(AUX.c_str());
										total += valor;
										delete aux;
										aux = new char[32];
										sprintf(aux,"%.03f",valor);
										aux[strlen(aux)-1] = '\0';
										cout << __FILE__ << ": " << __LINE__ << endl;
										AUX.clear();
										AUX = casa_milhar(aux,0);
										delete aux;
										aux = new char[AUX.length()+1];
										strcpy(aux,AUX.c_str());
										break;
										}
									}
								HPDF_Page_TextRect (this->Pagina,this->coluna[j][0], x, this->coluna[j][1], 15, converter(aux,1), this->Alinhamento, NULL);
								HPDF_Page_EndText (this->Pagina);
								delete aux;
								}
							break;
							}
						}
					x -= 15;
					if ((irg < this->conexao->resultados.end())&&(rg < (this->total_reg-1)))
						{
						cout << rg << " == " << this->total_reg << endl;
						irg++;
						linha = *irg;
						}
					rg++;
					
					//cout << rg << " de " << this->total_reg << endl;
					if (rg > (this->total_reg-1))
						{
						//cout << "estou aki" << endl;
						switch(this->tipo_relatorio)
							{
							case 1:
							case 2:
							case 3:
								{
								if (r >= 48)
									{
									this->set_rodape ();
									x = 765;
									this->pag++;
									this->Pagina = HPDF_AddPage (this->PDF_doc);
									HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

								  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
								  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

									this->set_cabecalho();
									//Setando fonte padrão
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
								  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									}
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								x -= 15;
								this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
								HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
								HPDF_Page_BeginText (this->Pagina);
								aux = new char[32];
								sprintf(aux,"%.02f",total);
								AUX.clear();
								AUX = casa_milhar(aux,0);
								delete aux;
								AUX = "Totalizando R$ "+AUX;
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								HPDF_Page_TextOut (this->Pagina, 15, x, converter(aux,1));
								delete aux;
								HPDF_Page_EndText (this->Pagina);
								break;
								}
							case 4:
								{
								if (r >= 47)
									{
									this->set_rodape ();
									x = 765;
									this->pag++;
									this->Pagina = HPDF_AddPage (this->PDF_doc);
									HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

								  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
								  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

									this->set_cabecalho();
									//Setando fonte padrão
									this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
								  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
									}
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								this->resumo(&x,&r);
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								this->pag++;
								break;
								}
							case 6:
							case 7:
							case 8:
							case 9:
							case 14:
								{
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								this->resumo(&x,&r);
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								break;
								}
							/*case 8:
								{
								HPDF_Page_MoveTo (this->Pagina, 15, x);
							  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, x);
							  	HPDF_Page_Stroke (this->Pagina);
								x -= 15;
								r++;
								this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
								HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
								HPDF_Page_BeginText (this->Pagina);
								aux = new char[32];
								sprintf(aux,"%d",this->total_reg);
								AUX.clear();
								AUX = casa_milhar(aux,1);
								delete aux;
								AUX = "Total de ocorrências: "+AUX;
								aux = new char[AUX.length()+1];
								strcpy(aux,AUX.c_str());
								HPDF_Page_TextOut (this->Pagina, 15, x, converter(aux,1));
								delete aux;
								HPDF_Page_EndText (this->Pagina);
								break;
								}*/
							}
						i=this->pags;
						break;
						}
					}
				}
			this->set_rodape();
			}
		}
	}

/**
 * \param modo indica como será o carregamento da informações.\n
 * 1 - Usuário Logado\n
 * 2 - Usuário Selecionado\n
 */
void PDFNEW::dados_funcionario(int modo)
	{
	char *aux;
	string AUX;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	switch(modo)
		{
		case 1:
			{
			AUX.clear();
			AUX = "select nome, acesso from cadastro.funcionario where cod_fun=";
			aux = new char[4];
			sprintf(aux,"%d",this->cod_fun);
			AUX.append(aux);
			delete aux;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->conexao->executar(aux);
			delete aux;
			if (this->conexao->query_result == 3)
				{
				cout << this->conexao->mensagem << endl;
				}
			else
				{
				this->conexao->resultado();
				ir = this->conexao->resultados.begin();
				if (ir < this->conexao->resultados.end())
					{
					linha = *ir;
					this->nome_fun.clear();
					this->nome_fun = linha.at(0);
					this->nivel_acesso = atoi(linha.at(1).c_str());
					}
				}
			break;
			}
		case 2:
			{
			AUX.clear();
			AUX = "select nome, u_login from cadastro.funcionario where cod_fun="+this->cod_funcionario;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			this->conexao->executar(aux);
			delete aux;
			if (this->conexao->query_result == 3)
				{
				cout << this->conexao->mensagem << endl;
				}
			else
				{
				this->conexao->resultado();
				ir = this->conexao->resultados.begin();
				if (ir < this->conexao->resultados.end())
					{
					linha = *ir;
					this->nome_funcionario.clear();
					this->nome_funcionario = linha.at(0);
					this->login_funcionario.clear();
					this->login_funcionario = linha.at(1);
					}
				}
			break;
			}
		}
	}

/**
 * Carrega os dados do serviço selecionado para impressão.
 */
void PDFNEW::dados_servico()
	{
	char *aux;
	string AUX;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	AUX.clear();
	AUX = "select codigo, descricao from cadastro.servicos where cod_serv="+this->cod_servico;
	aux = new char[AUX.length()+1];
	strcpy(aux,AUX.c_str());
	this->conexao->executar(aux);
	delete aux;
	if (this->conexao->query_result == 3)
		{
		cout << this->conexao->mensagem << endl;
		}
	else
		{
		this->conexao->resultado();
		ir = this->conexao->resultados.begin();
		if (ir < this->conexao->resultados.end())
			{
			linha = *ir;
			this->codigo_servico.clear();
			this->codigo_servico = linha.at(0);
			this->desc_servico.clear();
			this->desc_servico = linha.at(1);
			}
		}
	}

/**
 * Carrega os dados do cliente selecionado para impressão.
 */
void PDFNEW::dados_cliente()
	{
	char *aux;
	string AUX;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	AUX.clear();
	AUX = "select nome from cadastro.clientes where cod_cli="+this->cod_cliente;
	aux = new char[AUX.length()+1];
	strcpy(aux,AUX.c_str());
	this->conexao->executar(aux);
	delete aux;
	if (this->conexao->query_result == 3)
		{
		cout << this->conexao->mensagem << endl;
		}
	else
		{
		this->conexao->resultado();
		ir = this->conexao->resultados.begin();
		if (ir < this->conexao->resultados.end())
			{
			linha = *ir;
			this->nome_cliente.clear();
			this->nome_cliente = linha.at(0);
			}
		}
	}

/**
 * \param rec número do recibo
 * \param data data do recibo
 * \param r controle de registros por página
 * \param x posição do texto em largura
 */
void PDFNEW::detalhamento(const char *rec, const char *data, int *r, int *x)
	{
	string SQL, AUX;
	char *sql, *aux;
	int i, total;
	float valor;
	BANCOPG *detalhe;
	vector<vector<string> >::iterator ir;
	vector<string> linha;
	int it;
			
	detalhe = new BANCOPG(CONF_FILE);
	switch(this->tipo_relatorio)
		{
		case 4:
			{
			SQL.clear();
			SQL = "select servicos.descricao, entrada.qtd, entrada.total from caixa.entrada inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv where entrada.e_s=1 and entrada.rec=";
			SQL.append(rec);
			SQL += "and entrada.data='";
			SQL.append(data);
			SQL +="' order by servicos.descricao";
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			detalhe->executar(sql);
			if (detalhe->query_result == 3)
				{
				cout << detalhe->mensagem << endl;
				}
			else
				{
				total = detalhe->registros;
				detalhe->resultado();
				for (i=0,ir=detalhe->resultados.begin(); i < total,ir < detalhe->resultados.end(); i++,ir++)
					{
					*r = *r + 1;
					linha = *ir;
					if (*r >= 48)
						{
						this->set_rodape ();
						*r = 1;
						*x = 765;
						this->pag++;
						this->Pagina = HPDF_AddPage (this->PDF_doc);
						HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

					  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
					  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

						this->set_cabecalho();
						//Setando fonte padrão
						this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
					  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
						}
					HPDF_Page_BeginText (this->Pagina);
					HPDF_Page_SetTextLeading (this->Pagina, 12);
					AUX.clear();
					AUX = linha.at(0);
					aux = new char[AUX.length()+1];
					strcpy(aux,AUX.c_str());
					HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
					HPDF_Page_EndText (this->Pagina);
					delete aux;
					HPDF_Page_BeginText (this->Pagina);
					HPDF_Page_SetTextLeading (this->Pagina, 12);
					AUX.clear();
					AUX = linha.at(1);
					aux = new char[AUX.length()+1];
					strcpy(aux,AUX.c_str());
					HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], *x, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
					HPDF_Page_EndText (this->Pagina);
					delete aux;
					HPDF_Page_BeginText (this->Pagina);
					HPDF_Page_SetTextLeading (this->Pagina, 12);
					AUX.clear();
					AUX = linha.at(2);
					it = AUX.find(".");
					if (it != string::npos)
						{
						AUX.replace(it,1,",");
						}
					valor = atof(AUX.c_str());
					aux = new char[32];
					sprintf(aux,"%.03f",valor);
					aux[strlen(aux)-1] = '\0';
					cout << __FILE__ << ": " << __LINE__ << endl;
					AUX.clear();
					AUX = casa_milhar(aux,0);
					delete aux;
					aux = new char[AUX.length()+1];
					strcpy(aux,AUX.c_str());
					HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], *x, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
					HPDF_Page_EndText (this->Pagina);
					delete aux;
					*x -= 15;
					}
				}
			break;
			}
		}
	delete detalhe;
	}

/**
 * \param x posição do texto em largura
 * \param r controle de registros por página
 */ 
void PDFNEW::resumo(int *x, int *r)
	{
	string SQL, AUX;
	char *sql, *aux;
	int it,i, total;
	float valor;
	BANCOPG *resumo;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	resumo = new BANCOPG(CONF_FILE);
	switch(this->tipo_relatorio)
		{
		case 4:
			{
			SQL.clear();
			SQL = "select count(*) as total, sum(lancamentos.total) from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli where lancamentos.e_s=1 and lancamentos.tipo='C' and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' and lancamentos.status";
			if (this->cod_cliente.length() > 0)
				{
				SQL += " and lancamentos.cod_cli=" + this->cod_cliente;
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			resumo->executar(sql);
			if (resumo->query_result == 3)
				{
				cout << resumo->mensagem << endl;
				}
			else
				{
				resumo->resultado();
				ir = resumo->resultados.begin();
				linha = *ir;
				AUX.clear();
				AUX = "Total de Ocorrências: ";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(0);
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				AUX.clear();
				AUX = casa_milhar(aux,1);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,128, *x, 165, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(1);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				AUX = "R$ "+AUX;
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,200, *x, 300, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				}
			break;
			}
		case 6:
			{
			SQL.clear();
			SQL = "select sum(entrada.total-(entrada.funjecc10+entrada.issqn)), sum(entrada.desconto), sum(entrada.total_liq-(entrada.funjecc10+entrada.issqn)), sum(lancamentos.funjecc3), sum(entrada.funjecc10), sum (entrada.issqn) ";
			SQL += "from caixa.lancamentos inner join caixa.entrada on lancamentos.e_s=entrada.e_s and lancamentos.rec=entrada.rec and lancamentos.data=entrada.data ";
			SQL += "where lancamentos.e_s=1 and data_qt >= '"+this->datas[0]+"' and data_qt <= '"+this->datas[1]+"' and status";
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			resumo->executar(sql);
			if (resumo->query_result == 3)
				{
				cout << resumo->mensagem << endl;
				}
			else
				{
				resumo->resultado();
				ir = resumo->resultados.begin();
				linha = *ir;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				AUX.clear();
				AUX = linha.at(0);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], *x, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(1);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				AUX.clear();
				AUX = "TOTAL LÍQUIDO DO PERÍODO: ";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(2);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,300, *x, 370, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				AUX.clear();
				AUX = "Funjecc (3%):";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(3);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,300, *x, 370, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				AUX.clear();
				AUX = "Funjecc (10%):";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(4);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,300, *x, 370, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				AUX.clear();
				AUX = "ISSQN (5%):";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(5);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,300, *x, 370, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				}
			break;
			}
		case 7:
			{
			SQL.clear();
			SQL = "select sum(total), count(*)";
			SQL += "from caixa.lancamentos ";
			SQL += "where status and e_s=2 and data >= '"+this->datas[0]+"' and data <= '"+this->datas[1]+"'";
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			resumo->executar(sql);
			if (resumo->query_result == 3)
				{
				cout << resumo->mensagem << endl;
				}
			else
				{
				//cout << *r << endl;
				if (*r >= 48)
					{
					this->set_rodape ();
					*x = 765;
					*r = 0;
					this->pag++;
					this->Pagina = HPDF_AddPage (this->PDF_doc);
					HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

				  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
				  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

					this->set_cabecalho();
					//Setando fonte padrão
					this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
				  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
					}
				resumo->resultado();
				ir = resumo->resultados.begin();
				linha = *ir;
				AUX.clear();
				AUX = "TOTAL LÍQUIDO DO PERÍODO:  Ocorrências:";
				AUX += linha.at(1);
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(0);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				AUX.clear();
				AUX = casa_milhar(aux,0);
				AUX = "R$ "+AUX;
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,300, *x, 400, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				}
			break;
			}
		case 8:
			{
			SQL.clear();
			SQL = "select count(*) as ocorrencia, sum(total) ";
			SQL += "from caixa.lancamentos ";
			SQL += "where e_s=1 and data >= '"+this->datas[0]+"' and data <= '"+this->datas[1]+"' ";
			if (this->cod_funcionario.length() > 0)
				{
				SQL += " and cod_fun="+this->cod_funcionario+" ";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			resumo->executar(sql);
			if (resumo->query_result == 3)
				{
				cout << resumo->mensagem << endl;
				}
			else
				{
				resumo->resultado();
				ir = resumo->resultados.begin();
				linha = *ir;
				AUX.clear();
				AUX = "Total de Ocorrências: ";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(0);
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				AUX.clear();
				AUX = casa_milhar(aux,1);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,128, *x, 185, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(1);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				AUX = "R$ "+AUX;
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,300, *x, 400, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				}
			break;
			}
		case 9:
			{
			SQL.clear();
			SQL = "select count(*) as registros, sum(total) as total ";
			SQL += "from caixa.lancamentos ";
			SQL += "where lancamentos.e_s=1 and lancamentos.tipo='D' and lancamentos.data_qt >= '"+this->datas[0]+"' and lancamentos.data_qt <= '"+this->datas[1]+"' and lancamentos.status ";
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			resumo->executar(sql);
			if (resumo->query_result == 3)
				{
				cout << resumo->mensagem << endl;
				}
			else
				{
				resumo->resultado();
				ir = resumo->resultados.begin();
				linha = *ir;
				AUX.clear();
				AUX = "Total de Ocorrências: ";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 128, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(0);
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				AUX.clear();
				AUX = casa_milhar(aux,1);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,128, *x, 185, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(1);
				it = AUX.find(".");
				if (it != string::npos)	
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], *x, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				}
			break;
			}
		case 14:
			{
			SQL.clear();
			SQL = "select count(rec) as contagem, sum(total) as total, sum(total_liq) as total_liq, sum(s_issqn) as baseissqn, sum(s_issqn*0.05) as issqn from caixa.lancamentos where ";
			SQL += "data_qt >= '"+this->datas[0]+"' and data_qt <= '"+this->datas[1]+"' and lancamentos.status and cod_cli="+ this->cod_cliente;
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			resumo->executar(sql);
			if (resumo->query_result == 3)
				{
				cout << resumo->mensagem << endl;
				}
			else
				{
				resumo->resultado();
				ir = resumo->resultados.begin();
				linha = *ir;
				AUX.clear();
				AUX = "Total de Ocorrências: ";
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);
				HPDF_Page_TextRect (this->Pagina,15, *x, 128, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(0);
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				AUX.clear();
				AUX = casa_milhar(aux,1);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,128, *x, 180, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(1);
				it = AUX.find(".");
				if (it != string::npos)	
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], *x, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(2);
				it = AUX.find(".");
				if (it != string::npos)	
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], *x, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(3);
				it = AUX.find(".");
				if (it != string::npos)	
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 12);					
				AUX.clear();
				AUX = linha.at(4);
				it = AUX.find(".");
				if (it != string::npos)	
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux = new char[32];
				sprintf(aux,"%.03f",valor);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				aux = new char[AUX.length()+1];
				strcpy(aux,AUX.c_str());
				HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], *x, this->coluna[5][1], 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				delete aux;
				*x -= 15;
				*r = *r+1;
				}
			break;
			}
		}
	delete resumo;
	}

/**
 *
 */
int PDFNEW::contar_selos (int servico)
	{
	string SQL, AUX;
	char *sql, *aux;
	BANCOMY *protesto;
	BANCOMY *notas;
	BANCOMY *selos;
	int retorno;

	retorno = 0;
	SQL.clear();
	//cout << servico << endl;
	switch(servico)
		{
		case 1:
			{
			notas = new BANCOMY(CONF_FILE2);
			SQL = "select selo_numero from emitidas where data_impr>='"+this->datas[0]+"' and data_impr<='"+this->datas[1]+"' and tipo like 'Reconhe%' ";
			if (this->tipo_relatorio == 10)
				{
				SQL += "and usu_impr='"+this->nome_funcionario+"'";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			notas->executar(sql,2);
			delete sql;
			if (notas->query_result == 3)
				{
				cout << SQL << endl;
				cout << notas->mensagem << endl;
				}
			else
				{
				retorno = notas->registros;
				}
			delete notas;
			break;
			}
		case 2:
			{
			notas = new BANCOMY(CONF_FILE2);
			SQL = "select selo_numero from emitidas where data_impr>='"+this->datas[0]+"' and data_impr<='"+this->datas[0]+"' and tipo like 'Autenticacao' ";
			if (this->tipo_relatorio == 10)
				{
				SQL += "and usu_impr='"+this->nome_funcionario+"'";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			notas->executar(sql,2);
			delete sql;
			if (notas->query_result == 3)
				{
				cout << SQL << endl;
				cout << notas->mensagem << endl;
				}
			else
				{
				retorno = notas->registros;
				}
			delete notas;
			break;
			}
		case 3:
			{
			notas = new BANCOMY(CONF_FILE2);
			SQL = "select ficha from firmas where data_inclu>='"+this->datas[0]+"' and data_inclu<='"+this->datas[0]+"' ";
			if (this->tipo_relatorio == 10)
				{
				SQL += " and digitador='"+this->login_funcionario+"'";
				}	
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			notas->executar(sql,2);
			delete sql;
			if (notas->query_result == 3)
				{
				cout << SQL << endl;
				cout << notas->mensagem << endl;
				}
			else
				{
				retorno = notas->registros;
				}
			delete notas;
			break;
			}
		case 6:
			{
			protesto = new BANCOMY(CONF_FILE1);
			SQL = "select numero from pt_pedid where data>='"+this->datas[0]+"' and data<='"+this->datas[1]+"' and (tipo_cert like 'Certid%' or tipo_cert like 'Breve%')";
			if (this->tipo_relatorio == 10)
				{
				SQL += " and usuario='"+this->login_funcionario+"' ";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			protesto->executar(sql,2);
			delete sql;
			if (protesto->query_result == 3)
				{
				cout << SQL << endl;
				cout << protesto->mensagem << endl;
				}
			else
				{
				retorno = protesto->registros;
				}
			delete protesto;
			break;
			}
		case 7:
			{
			protesto = new BANCOMY(CONF_FILE1);
			SQL = "select numero from pt_pedid where data>='"+this->datas[0]+"' and data<='"+this->datas[1]+"' and tipo_cert like 'Cancelamento%'";
			if (this->tipo_relatorio == 10)
				{
				SQL += "and usuario='"+this->login_funcionario+"'";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			protesto->executar(sql,2);
			delete sql;
			if (protesto->query_result == 3)
				{
				cout << SQL << endl;
				cout << protesto->mensagem << endl;
				}
			else
				{
				retorno = protesto->registros;
				}
			delete protesto;
			break;
			}
		case 10:
			{
			protesto = new BANCOMY(CONF_FILE1);
			SQL = "select protocolo from pt_mov where data_re>='"+this->datas[0]+"' and data_re<='"+this->datas[1]+"' ";
			if (this->tipo_relatorio == 10)
				{
				SQL += " and identific1 like '"+this->login_funcionario+"%'";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			protesto->executar(sql,2);
			delete sql;
			if (protesto->query_result == 3)
				{
				cout << SQL << endl;
				cout << protesto->mensagem << endl;
				}
			else
				{
				retorno = protesto->registros;
				}
			delete protesto;
			break;
			}
		/*case 14:
			{
			selos = new BANCOMY(CONF_FILE3);
			SQL = "select row_id from selosutils2 where data_ato='"+this->data_sel+"' and id_ato like '"+this->n_login+"%'";
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			selos->executar(sql,2);
			delete sql;
			if (selos->query_result == 3)
				{
				cout << selos->mensagem << endl;
				}
			else
				{
				retorno = selos->registros;
				}
			delete selos;
			break;
			}*/
		case 19:
			{
			notas = new BANCOMY(CONF_FILE2);
			SQL = "select nr_protoc from certidao where data>='"+this->datas[0]+"' and data<='"+this->datas[1]+"' ";
			if (this->tipo_relatorio == 10)
				{
				SQL += " and identifica='"+this->login_funcionario+"'";
				}
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			notas->executar(sql,2);
			delete sql;
			if (notas->query_result == 3)
				{
				cout << SQL << endl;
				cout << notas->mensagem << endl;
				}
			else
				{
				retorno = notas->registros;
				}
			delete notas;
			break;
			}
		}
	if (this->tipo_relatorio == 11)
		{
		switch(servico)
			{
			case 11:
				{
				protesto = new BANCOMY(CONF_FILE1);
				SQL = "select recno from pt_ment where data>='"+this->datas[0]+"' and data<='"+this->datas[1]+"' and titulos='PROTESTOS'";
				sql = new char[SQL.length()+1];
				strcpy(sql,SQL.c_str());
				//cout << sql << endl;
				protesto->executar(sql,2);
				delete sql;
				if (protesto->query_result == 3)
					{
					cout << SQL << endl;
					cout << protesto->mensagem << endl;
					}
				else
					{
					retorno = protesto->registros;
					}
				delete protesto;
				break;
				}
			case 12:
				{
				protesto = new BANCOMY(CONF_FILE1);
				SQL = "select recno from pt_ment where data>='"+this->datas[0]+"' and data<='"+this->datas[1]+"' and titulos='CANCELADOS'";
				sql = new char[SQL.length()+1];
				strcpy(sql,SQL.c_str());
				//cout << sql << endl;
				protesto->executar(sql,2);
				delete sql;
				if (protesto->query_result == 3)
					{
					cout << SQL << endl;
					cout << protesto->mensagem << endl;
					}
				else
					{
					retorno = protesto->registros;
					}
				delete protesto;
				break;
				}
			case 14:
				{
				selos = new BANCOMY(CONF_FILE3);
				SQL = "select row_id from selosutils2 where data_ato>='"+this->datas[0]+"' and data_ato<='"+this->datas[1]+"' and (id_ato=103 or id_ato=104)";
				sql = new char[SQL.length()+1];
				strcpy(sql,SQL.c_str());
				//cout << sql << endl;
				selos->executar(sql,2);
				delete sql;
				if (selos->query_result == 3)
					{
					cout << selos->mensagem << endl;
					}
				else
					{
					retorno = selos->registros;
					}
				delete selos;
				break;
				}
			case 15:
				{
				selos = new BANCOMY(CONF_FILE3);
				SQL = "select row_id from selosutils2 where data_ato>='"+this->datas[0]+"' and data_ato<='"+this->datas[1]+"' and id_ato=107";
				sql = new char[SQL.length()+1];
				strcpy(sql,SQL.c_str());
				//cout << sql << endl;
				selos->executar(sql,2);
				delete sql;
				if (selos->query_result == 3)
					{
					cout << selos->mensagem << endl;
					}
				else
					{
					retorno = selos->registros;
					}
				delete selos;
				break;
				}
			case 28:
				{
				selos = new BANCOMY(CONF_FILE3);
				SQL = "select row_id from selosutils2 where data_ato>='"+this->datas[0]+"' and data_ato<='"+this->datas[1]+"' and id_ato=108";
				sql = new char[SQL.length()+1];
				strcpy(sql,SQL.c_str());
				//cout << sql << endl;
				selos->executar(sql,2);
				delete sql;
				if (selos->query_result == 3)
					{
					cout << selos->mensagem << endl;
					}
				else
					{
					retorno = selos->registros;
					}
				delete selos;
				break;
				}
			}
		}
	return (retorno);
	}

/**
 * /param servico
 */
string PDFNEW::contagem(string servico)
	{
	BANCOPG *conta;
	string SQL,AUX;
	char *sql;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	conta = new BANCOPG(CONF_FILE);
	SQL = "select count(*) from caixa.lancamentos inner join caixa.entrada on lancamentos.e_s=entrada.e_s and lancamentos.rec=entrada.rec and lancamentos.data=entrada.data inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv where ";
	SQL += "servicos.codigo = " + servico;
	if (this->cod_funcionario.length() > 0)
		{
		SQL += "and lancamentos.cod_fun=" + this->cod_funcionario;
		}
	SQL += " and lancamentos.data >= '"+this->datas[0]+"' and lancamentos.data <= '"+this->datas[1]+"' ";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	conta->executar(sql);
	delete sql;
	if (conta->query_result == 3)
		{
		AUX.clear();
		AUX += conta->mensagem;
		}
	else
		{
		conta->resultado();
		ir = conta->resultados.begin();
		linha = *ir;
		AUX.clear();
		AUX = linha.at(0);
		}
	delete conta;
	return (AUX);
	}

/**
 *
 */
void PDFNEW::relatorio_escr(int *r, int *x)
	{
	BANCOMY *notas;
	BANCOMY *selos;
	string AUX, SQL, TIPO, bs;
	char *sql, *aux, *vlr, *aux_vlr;
	int total, v_valor, v, i, ES, PR, it;
	float vlr_cert, valor, t_total, *v_aux ,v_fpe , v_red ,totais[]={0.0,0.0,0.0,0.0,0.0,0.0};
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	total = 0;
	vlr = new char[64];
	SQL.clear();
	SQL = "select valor_u from cadastro.servicos where cod_serv=19";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	this->conexao->executar(sql);
	delete sql;
	this->conexao->resultado();
	ir = this->conexao->resultados.begin();
	linha = *ir;
	AUX.clear();
	AUX = linha.at(0);
	it = AUX.find(".");
	if (it != string::npos)
		{
		AUX.replace(it,1,",");
		}
	vlr_cert = atof(AUX.c_str());
	notas = new BANCOMY(CONF_FILE2);
	selos = new BANCOMY(CONF_FILE3);
	SQL.clear();
	SQL = "select data, livro, folha, sel_serie, sel_num, sel_dv, isento from certidao where data>='"+this->datas[0]+"' and data<='"+this->datas[1]+"' and status='PRONTO'";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	notas->executar(sql,2);
	//cout << sql << endl;
	//cout << notas->mensagem << endl;
	delete sql;
	if (notas->query_result != 3)
		{
		for (i=0; i < notas->registros; i++)
			{
			total++;
			t_total = 0.0;
			notas->resultado();
			if (notas->resultados[6].compare("S") == 0)
				{
				valor = 0;
				}
			else
				{
				valor = vlr_cert;
				}
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = notas->resultados[0];
			//cout << notas->resultados[0] << endl;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			aux = data_formatada(aux,2);
			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux = new char[2];
			strcpy(aux,"C");
			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], *x, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = notas->resultados[1];
			//cout << notas->resultados[0] << endl;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], *x, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = notas->resultados[2] + " a "+ notas->resultados[2];
			//cout << notas->resultados[0] << endl;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], *x, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor);
			vlr[strlen(vlr)-1] = '\0';
			totais[0] += valor;
			HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			totais[1] += valor;
			t_total += valor;
			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], *x, this->coluna[5][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor*0.1);
			vlr[strlen(vlr)-1] = '\0';
			totais[2] += (valor*0.1);
			t_total += (valor*0.1);
			HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], *x, this->coluna[6][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor*0.03);
			vlr[strlen(vlr)-1] = '\0';
			HPDF_Page_TextRect (this->Pagina,this->coluna[7][0], *x, this->coluna[7][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor*0.05);
			vlr[strlen(vlr)-1] = '\0';
			totais[3] += (valor*0.05);
			t_total += (valor*0.05);
			HPDF_Page_TextRect (this->Pagina,this->coluna[8][0], *x, this->coluna[8][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",0.0);
			vlr[strlen(vlr)-1] = '\0';
			totais[4] += 0.0;
			t_total += 0.0;
			HPDF_Page_TextRect (this->Pagina,this->coluna[9][0], *x, this->coluna[9][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",t_total);
			vlr[strlen(vlr)-1] = '\0';
			totais[5] += t_total;
			HPDF_Page_TextRect (this->Pagina,this->coluna[10][0], *x, this->coluna[10][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			*x -= 15;
			*r = *r+1;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = "Selo Digital: " + notas->resultados[3] + " " + notas->resultados[4] +"-"+notas->resultados[5];
			//cout << notas->resultados[0] << endl;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1]+100, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			*x -= 15;
			*r = *r+1;	
			if (*r >= 48)
				{
				this->set_rodape ();
				*r = 1;
				*x = 765;
				this->pag++;
				this->Pagina = HPDF_AddPage (this->PDF_doc);
				HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

			  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
			  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

				this->set_cabecalho();
				//Setando fonte padrão
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				}
			}
		}
	delete notas;
	SQL.clear();
	SQL = "select selosutils.data_ato, selosutils.id_ato, selosutils.livro, selosutils.folha_i, selosutils.folha_f, selosutils2.prefixo_i, selosutils2.numero_i, selosutils2.dv, selosutils.referencia,selosutils.vr_transacao, selosutils.vr_reducao, selosutils.isento from selosutils inner join selosutils2 on selosutils.referencia=selosutils2.referencia where selosutils.data_ato>='"+this->datas[0]+"' and selosutils.data_ato<='"+this->datas[1]+"' and (selosutils.id_ato=107 or selosutils.id_ato=108 or selosutils.id_ato=118) order by selosutils.livro, selosutils.folha_i";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	//cout << sql << endl;
	selos->executar(sql,2);
	if (selos->query_result != 3)
		{
		for (i=0; i < selos->registros; i++)
			{
			total++;
			t_total = 0.0;
			v_fpe = 0.0;
			v_red = 0.0;
			selos->resultado();
			if (selos->resultados[10].length() > 0)
				{
				AUX.clear();
				AUX = selos->resultados[10];
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				v_red = atof(AUX.c_str ());
				}
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = selos->resultados[0];
			//cout << notas->resultados[0] << endl;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			aux = data_formatada(aux,2);
			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			TIPO.clear();
			if (selos->resultados[1].compare("107") == 0)
				{
				TIPO = "P";
				}
			else if (selos->resultados[1].compare("108") == 0)
				{
				TIPO = "PP";
				}
			else if (selos->resultados[1].compare("118") == 0)
				{
				TIPO = "PCP";
				}
			else
				{
				TIPO = " ";
				}
			valor = this->valor_servico (1,selos->resultados[1]);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux = new char[32];
			strcpy(aux,TIPO.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], *x, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = selos->resultados[2];
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], *x, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = selos->resultados[3] + " a "+ selos->resultados[4];
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], *x, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			if (selos->resultados[1].compare("118") == 0)
				{
				v_valor = this->bases_escritura(selos->resultados[8]);
				AUX.clear();
				AUX = selos->resultados[9];
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux_vlr = new char[32];
				sprintf(aux_vlr,"%0.3f",valor);
				aux_vlr[strlen(aux_vlr)-1] = '\0';
				AUX.clear();
				AUX = casa_milhar(aux_vlr,0);
				delete aux_vlr;
				bs.clear();
				bs = AUX + "\n";
				v_aux = new float[v_valor+1];
				v_aux[0] = valor;
				for (v=0; v < v_valor; v++)
					{
					AUX.clear();
					AUX = BASES[v];
					it = AUX.find(".");
					if (it != string::npos)
						{
						AUX.replace(it,1,",");
						}
					v_aux[v+1] = atof(AUX.c_str());
					aux_vlr = new char[32];
					sprintf(aux_vlr,"%0.3f",v_aux[v+1]);
					aux_vlr[strlen(aux_vlr)-1] = '\0';
					AUX.clear();
					AUX = casa_milhar(aux_vlr,0);
					delete aux_vlr;
					bs += AUX + "\n";
					valor += v_aux[v+1];
					}
				if (valor > 50000.00)
					{
					v_fpe = this->valor_servico (1,"1");
					}
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				aux_vlr = new char[bs.length()+1];
				strcpy(aux_vlr,bs.c_str());
				totais[0] += valor;
				HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(aux_vlr,1), HPDF_TALIGN_RIGHT, NULL);
				delete aux_vlr;
				HPDF_Page_EndText (this->Pagina);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				if (selos->resultados[11].compare ("S") == 0)
					{
					valor = 0;
					}
				else
					{
					valor = this->valor_servico (2,"104", v_valor, v_aux);
					}
				if (valor > 7331.00)
					{
					valor = 7331.00;
					}
				delete v_aux;
				valor -= v_red;
				aux_vlr = new char[32];
				sprintf(aux_vlr,"%0.3f",valor);
				aux_vlr[strlen(aux_vlr)-1] = '\0';
				AUX.clear();
				AUX = casa_milhar(aux_vlr,0);
				delete aux_vlr;
				strcpy(vlr,AUX.c_str());
				//cout << valor << endl;
				totais[1] += valor;
				t_total += valor;
				}
			else
				{
				v_valor = 0;
				if (selos->resultados[11].compare("S") == 0)
					{
					valor = 0;
					}
				else
					{
					valor = this->valor_servico (2,selos->resultados[1]);
					}
				valor -= v_red;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				delete vlr;
				vlr = new char[32];
				sprintf(vlr,"%0.3f",valor);
				vlr[strlen(vlr)-1] = '\0';
				totais[0] += valor;
				HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				totais[1] += valor;
				t_total += valor;
				}
			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], *x, this->coluna[5][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor*0.1);
			vlr[strlen(vlr)-1] = '\0';
			totais[2] += (valor*0.1);
			t_total += (valor*0.1);
			HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], *x, this->coluna[6][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor*0.03);
			vlr[strlen(vlr)-1] = '\0';
			HPDF_Page_TextRect (this->Pagina,this->coluna[7][0], *x, this->coluna[7][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",valor*0.05);
			vlr[strlen(vlr)-1] = '\0';
			totais[3] += (valor*0.05);
			t_total += (valor*0.05);
			HPDF_Page_TextRect (this->Pagina,this->coluna[8][0], *x, this->coluna[8][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",v_fpe);
			vlr[strlen(vlr)-1] = '\0';
			totais[4] += v_fpe;
			t_total += v_fpe;
			HPDF_Page_TextRect (this->Pagina,this->coluna[9][0], *x, this->coluna[9][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",t_total);
			vlr[strlen(vlr)-1] = '\0';
			totais[5] += t_total;
			HPDF_Page_TextRect (this->Pagina,this->coluna[10][0], *x, this->coluna[10][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			*x -= 15;
			*r = *r+1;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = "Selo Digital: " + selos->resultados[5] + " " + selos->resultados[6] +"-"+selos->resultados[7];
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1]+100, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			*x -= 15;
			*r = *r+1;
			if (*r >= 48)
				{
				this->set_rodape ();
				*r = 1;
				*x = 765;
				this->pag++;
				this->Pagina = HPDF_AddPage (this->PDF_doc);
				HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

			  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
			  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

				this->set_cabecalho();
				//Setando fonte padrão
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				}
			}
		}
	PR = 0;
	if (selos->registros > 0)
		{
		PR = atoi(selos->resultados[4].c_str());
		}
	//cout << PR << endl;
	PR++;
	SQL.clear();
	SQL = "select selosutils.data_ato, selosutils.id_ato, selosutils.livro, selosutils.folha_i, selosutils.folha_f, selosutils2.prefixo_i, selosutils2.numero_i, selosutils2.dv, selosutils.referencia, selosutils.vr_transacao, selosutils.vr_reducao, selosutils.isento from selosutils inner join selosutils2 on selosutils.referencia=selosutils2.referencia where selosutils.data_ato>='"+this->datas[0]+"' and selosutils.data_ato<='"+this->datas[1]+"' and (selosutils.id_ato=103 or selosutils.id_ato=104 or selosutils.id_ato=105 or selosutils.id_ato=106 or selosutils.id_ato=113) order by selosutils.livro, selosutils.folha_i";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	//cout << sql << endl;
	selos->executar(sql,2);
	if (selos->query_result != 3)
		{
		for (i=0; i < selos->registros; i++)
			{
			total++;
			t_total = 0.0;
			v_fpe = 0.0;
			v_red = 0.0;
			selos->resultado();
			if (selos->resultados[10].length() > 0)
				{
				AUX.clear();
				AUX = selos->resultados[10];
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				v_red = atof(AUX.c_str ());
				}
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = selos->resultados[0];
			//cout << notas->resultados[0] << endl;
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			aux = data_formatada(aux,2);
			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			TIPO.clear();
			if (selos->resultados[1].compare("103") == 0)
				{
				TIPO = "ES";
				}
			else if (selos->resultados[1].compare("104") == 0)
				{
				TIPO = "E";
				}
			else if (selos->resultados[1].compare("105") == 0)
				{
				TIPO = "ET";
				}
			else if (selos->resultados[1].compare("106") == 0)
				{
				TIPO = "ET";
				}
			else if (selos->resultados[1].compare("113") == 0)
				{
				TIPO = "EA";
				}
			else
				{
				TIPO = " ";
				}
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux = new char[32];
			strcpy(aux,TIPO.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[1][0], *x, this->coluna[1][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = selos->resultados[2];
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[2][0], *x, this->coluna[2][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = selos->resultados[3] + " a "+ selos->resultados[4];
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[3][0], *x, this->coluna[3][1], 15, converter(aux,1), HPDF_TALIGN_CENTER, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			if (selos->resultados[1].compare("104") == 0)
				{
				v_valor = this->bases_escritura(selos->resultados[8]);
				AUX.clear();
				AUX = selos->resultados[9];
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				aux_vlr = new char[32];
				sprintf(aux_vlr,"%0.3f",valor);
				aux_vlr[strlen(aux_vlr)-1] = '\0';
				AUX.clear();
				AUX = casa_milhar(aux_vlr,0);
				delete aux_vlr;
				bs.clear();
				bs = AUX + "\n";
				v_aux = new float[v_valor+1];
				v_aux[0] = valor;
				for (v=0; v < v_valor; v++)
					{
					AUX.clear();
					AUX = BASES[v];
					it = AUX.find(".");
					if (it != string::npos)
						{
						AUX.replace(it,1,",");
						}
					v_aux[v+1] = atof(AUX.c_str());
					aux_vlr = new char[32];
					sprintf(aux_vlr,"%0.3f",v_aux[v+1]);
					aux_vlr[strlen(aux_vlr)-1] = '\0';
					AUX.clear();
					AUX = casa_milhar(aux_vlr,0);
					delete aux_vlr;
					bs += AUX + "\n";
					valor += v_aux[v+1];
					}
				if (valor > 50000.00)
					{
					v_fpe = this->valor_servico (1,"1");
					}
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				aux_vlr = new char[bs.length()+1];
				strcpy(aux_vlr,bs.c_str());
				totais[0] += valor;
				HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(aux_vlr,1), HPDF_TALIGN_RIGHT, NULL);
				delete aux_vlr;
				HPDF_Page_EndText (this->Pagina);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				if (selos->resultados[11].compare("S") == 0)
					{
					valor = 0;
					}
				else
					{
					valor = this->valor_servico (2,selos->resultados[1], v_valor, v_aux);
					}
				if (valor > 7331.00)
					{
					valor = 7331.00;
					}
				delete v_aux;
				valor -= v_red;
				aux_vlr = new char[32];
				sprintf(aux_vlr,"%0.3f",valor);
				aux_vlr[strlen(aux_vlr)-1] = '\0';
				AUX.clear();
				AUX = casa_milhar(aux_vlr,0);
				delete aux_vlr;
				strcpy(vlr,AUX.c_str());
				//cout << valor << endl;
				totais[1] += valor;
				t_total += valor;
				}
			else
				{
				v_valor = 0;
				valor = this->valor_servico(2,selos->resultados[1]);
				if (selos->resultados[11].compare("S") == 0)
					{
					valor = 0;
					}
				else
					{
					valor = this->valor_servico (2,selos->resultados[1]);
					}
				valor -= v_red;
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				delete vlr;
				vlr = new char[32];
				if (selos->resultados[1].compare("103")==0)
					{
					sprintf(vlr,"%0.3f",0.0);
					vlr[strlen(vlr)-1] = '\0';
					totais[0] += 0.0;
					}
				else
					{
					sprintf(vlr,"%0.3f",valor);
					vlr[strlen(vlr)-1] = '\0';
					totais[0] += valor;
					}
				HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
				HPDF_Page_EndText (this->Pagina);
				HPDF_Page_BeginText (this->Pagina);
				HPDF_Page_SetTextLeading (this->Pagina, 10);
				delete vlr;
				vlr = new char[32];
				if (selos->resultados[1].compare("103")==0)
					{
					sprintf(vlr,"%0.3f",valor);
					vlr[strlen(vlr)-1] = '\0';
					}
				totais[1] += valor;
				t_total += valor;
				}
			HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], *x, this->coluna[5][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux_vlr = new char[32];
			sprintf(aux_vlr,"%0.3f",valor*0.1);
			aux_vlr[strlen(aux_vlr)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux_vlr,0);
			delete aux_vlr;
			delete vlr;
			vlr = new char[32];
			strcpy(vlr,AUX.c_str());
			totais[2] += (valor*0.1);
			t_total += (valor*0.1);
			HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], *x, this->coluna[6][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux_vlr = new char[32];
			sprintf(aux_vlr,"%0.3f",valor*0.03);
			aux_vlr[strlen(aux_vlr)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux_vlr,0);
			delete aux_vlr;
			delete vlr;
			vlr = new char[32];
			strcpy(vlr,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[7][0], *x, this->coluna[7][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux_vlr = new char[32];
			sprintf(aux_vlr,"%0.3f",valor*0.05);
			aux_vlr[strlen(aux_vlr)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux_vlr,0);
			delete aux_vlr;
			delete vlr;
			vlr = new char[32];
			strcpy(vlr,AUX.c_str());
			totais[3] += (valor*0.05);
			t_total += (valor*0.05);
			HPDF_Page_TextRect (this->Pagina,this->coluna[8][0], *x, this->coluna[8][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			delete vlr;
			vlr = new char[32];
			sprintf(vlr,"%0.3f",v_fpe);
			vlr[strlen(vlr)-1] = '\0';
			totais[4] += v_fpe;
			t_total += v_fpe;
			HPDF_Page_TextRect (this->Pagina,this->coluna[9][0], *x, this->coluna[9][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux_vlr = new char[32];
			sprintf(aux_vlr,"%0.3f",t_total);
			aux_vlr[strlen(aux_vlr)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux_vlr,0);
			delete aux_vlr;
			delete vlr;
			vlr = new char[32];
			strcpy(vlr,AUX.c_str());
			totais[5] += t_total;
			HPDF_Page_TextRect (this->Pagina,this->coluna[10][0], *x, this->coluna[10][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			*x -= 15;
			*r = *r+1;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);					
			AUX.clear();
			AUX = "Selo Digital: " + selos->resultados[5] + " " + selos->resultados[6] +"-"+selos->resultados[7];
			aux = new char[AUX.length()+1];
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1]+100, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			if (v_valor > 0)
				{
				*x = *x - (15 * v_valor) ;
				*r += v_valor;
				}
			else
				{
				*x -= 15;
				*r = *r+1;
				}
			if (*r >= 48)
				{
				this->set_rodape ();
				*r = 1;
				*x = 765;
				this->pag++;
				this->Pagina = HPDF_AddPage (this->PDF_doc);
				HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

			  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
			  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

				this->set_cabecalho();
				//Setando fonte padrão
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				}
			}
		}
	ES = 0;
	if (selos->registros > 0)
		{
		ES = atoi(selos->resultados[4].c_str());
		}
	//cout << ES << endl;
	ES++;
	//SQL.
	delete selos;
	HPDF_Page_MoveTo (this->Pagina, 15, *x);
  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, *x);
  	HPDF_Page_Stroke (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 9);
	AUX.clear();
	AUX = "Total de Ocorrências: ";
	aux = new char[12];
	sprintf (aux,"%d",total);
	AUX.append(aux);
	delete aux;
	aux = new char[AUX.length()+1];
	strcpy(aux,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1]+100, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
	HPDF_Page_EndText (this->Pagina);
	delete aux;
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	delete vlr;
	vlr = new char[32];
	sprintf(vlr,"%0.3f",totais[0]);
	vlr[strlen(vlr)-1] = '\0';
	AUX.clear();
	AUX = casa_milhar(vlr,0);
	delete vlr;
	vlr = new char[32];
	strcpy(vlr,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[4][0], *x, this->coluna[4][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
	HPDF_Page_EndText (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	delete vlr;
	vlr = new char[32];
	sprintf(vlr,"%0.3f",totais[1]);
	vlr[strlen(vlr)-1] = '\0';
	AUX.clear();
	AUX = casa_milhar(vlr,0);
	delete vlr;
	vlr = new char[32];
	strcpy(vlr,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[5][0], *x, this->coluna[5][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
	HPDF_Page_EndText (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	delete vlr;
	vlr = new char[32];
	sprintf(vlr,"%0.3f",totais[2]);
	vlr[strlen(vlr)-1] = '\0';
	AUX.clear();
	AUX = casa_milhar(vlr,0);
	delete vlr;
	vlr = new char[32];
	strcpy(vlr,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[6][0], *x, this->coluna[6][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
	HPDF_Page_EndText (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	delete vlr;
	vlr = new char[32];
	sprintf(vlr,"%0.3f",totais[3]);
	vlr[strlen(vlr)-1] = '\0';
	AUX.clear();
	AUX = casa_milhar(vlr,0);
	delete vlr;
	vlr = new char[32];
	strcpy(vlr,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[8][0], *x, this->coluna[8][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
	HPDF_Page_EndText (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	delete vlr;
	vlr = new char[32];
	sprintf(vlr,"%0.3f",totais[4]);
	vlr[strlen(vlr)-1] = '\0';
	AUX.clear();
	AUX = casa_milhar(vlr,0);
	delete vlr;
	vlr = new char[32];
	strcpy(vlr,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[9][0], *x, this->coluna[9][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
	HPDF_Page_EndText (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);
	delete vlr;
	vlr = new char[32];
	sprintf(vlr,"%0.3f",totais[5]);
	vlr[strlen(vlr)-1] = '\0';
	AUX.clear();
	AUX = casa_milhar(vlr,0);
	delete vlr;
	vlr = new char[32];
	strcpy(vlr,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[10][0], *x, this->coluna[10][1], 15, converter(vlr,1), HPDF_TALIGN_RIGHT, NULL);
	HPDF_Page_EndText (this->Pagina);
	delete vlr;
	*x = *x - 15;
	*r = *r + 1;
	if (*r >= 48)
		{
		this->set_rodape ();
		*r = 1;
		*x = 765;
		this->pag++;
		this->Pagina = HPDF_AddPage (this->PDF_doc);
		HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

	  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
	  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

		this->set_cabecalho();
		//Setando fonte padrão
		this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
	  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
		}
	HPDF_Page_MoveTo (this->Pagina, 15, *x);
  	HPDF_Page_LineTo (this->Pagina, this->Largura-20, *x);
  	HPDF_Page_Stroke (this->Pagina);
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);					
	AUX.clear();
	AUX = "Procuração: ";
	aux = new char[12];
	sprintf (aux,"%03d",PR);
	AUX.append(aux);
	delete aux;
	aux = new char[AUX.length()+1];
	strcpy(aux,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1]+100, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
	HPDF_Page_EndText (this->Pagina);
	delete aux;
	*x = *x - 15;
	*r = *r + 1;
	if (*r >= 48)
		{
		this->set_rodape ();
		*r = 1;
		*x = 765;
		this->pag++;
		this->Pagina = HPDF_AddPage (this->PDF_doc);
		HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

	  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
	  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

		this->set_cabecalho();
		//Setando fonte padrão
		this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
	  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
		}
	HPDF_Page_BeginText (this->Pagina);
	HPDF_Page_SetTextLeading (this->Pagina, 10);					
	AUX.clear();
	AUX = "Escrituras: ";
	aux = new char[12];
	sprintf (aux,"%03d",ES);
	AUX.append(aux);
	delete aux;
	aux = new char[AUX.length()+1];
	strcpy(aux,AUX.c_str());
	HPDF_Page_TextRect (this->Pagina,this->coluna[0][0], *x, this->coluna[0][1]+100, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
	HPDF_Page_EndText (this->Pagina);
	delete aux;
	if (this->nivel_acesso == 0)
		{
		this->dados_caixa(r,x);
		}
	}

/**
 *
 */
float PDFNEW::valor_servico(int tipo, string codigo, ...)
	{
	va_list argumento;
	string SQL, AUX;
	char *sql, *data, *aux;
	int codigo_a, n_bases, i, it;
	float *valor_base, valor_ret, valor;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	SQL.clear();
	if (tipo != 2)
		{
		SQL = "select valor from cadastro.tabela_servico where codigo="+codigo+" and data <= '"+this->datas[1]+"' order by data desc";
		sql = new char[SQL.length()+1];
		strcpy(sql,SQL.c_str());
		//cout << sql << endl;
		this->conexao->executar(sql);
		this->conexao->resultado();
		ir = this->conexao->resultados.begin();
		linha = *ir;
		AUX.clear();
		AUX = linha.at(0);
		it = AUX.find(".");
		if (it != string::npos)
			{
			AUX.replace(it,1,",");
			}
		return (atof(AUX.c_str()));
		}
	else
		{
		//cout << codigo << endl;
		if ((codigo.compare("104") != 0)&&(codigo.compare("118") != 0))
			{
			SQL = "select valor from cadastro.tabela_servico where codigo="+codigo+" and data <= '"+this->datas[1]+"' order by data desc";
			sql = new char[SQL.length()+1];
			strcpy(sql,SQL.c_str());
			//cout << sql << endl;
			this->conexao->executar(sql);
			this->conexao->resultado();
			ir = this->conexao->resultados.begin();
			linha = *ir;
			AUX.clear();
			AUX = linha.at(0);
			it = AUX.find(".");
			if (it != string::npos)
				{
				AUX.replace(it,1,",");
				}
			return (atof(AUX.c_str()));
			}
		else
			{
			data = new char[12];
			data = hoje();
			valor_ret = 0.0;
			va_start(argumento,2);
			n_bases = va_arg(argumento,int);
			valor_base = new float[n_bases+1];
			valor_base = va_arg(argumento,float *);
			va_end(argumento);
			for (i=0; i <= n_bases; i++)
				{
				//cout << valor_base[i] << endl;
				SQL.clear();
				SQL = "select valor from cadastro.tabela_notas where data <= '"+this->datas[1]+"' and codigo="+codigo+" and inicial <= '";
				aux = new char[32];
				sprintf (aux,"%f",valor_base[i]);
				AUX.clear();
				AUX = valor_formatado(aux,1);
				delete aux;
				SQL += AUX + "' and final >= '"+AUX+"' order by inicial ";
				//cout << SQL << endl;
				sql = new char[SQL.length()+1];
				strcpy(sql,SQL.c_str());
				this->conexao->executar(sql);
				this->conexao->resultado();
				ir = this->conexao->resultados.begin();
				linha = *ir;
				AUX.clear();
				AUX = linha.at(0);
				it = AUX.find(".");
				if (it != string::npos)
					{
					AUX.replace(it,1,",");
					}
				valor = atof(AUX.c_str());
				//cout << valor_base[i] << " = " << valor << endl;
				if (i > 0)
					{
					valor = valor/2;
					}
				//cout << i << "=" << valor << endl;
				valor_ret += valor;
				}
			delete data;
			return (valor_ret);
			}
		}
	}

/**
 *
 */
int PDFNEW::bases_escritura (string referencia)
	{
	BANCOMY *selos_b;
	string SQL, AUX;
	char *sql;
	int i, it;

	selos_b = new BANCOMY(CONF_FILE3);
	SQL.clear();
	SQL = "select base_calculo from base_calc where referencia="+referencia;
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	//cout << sql << endl;
	selos_b->executar(sql,2);
	delete sql;
	if (selos_b->registros > 0)
		{
		BASES = new string[selos_b->registros];
		for (i=0; i < selos_b->registros; i++)
			{
			selos_b->resultado();
			BASES[i].append(selos_b->resultados[0]);
			}
		return selos_b->registros;
		}
	else
		{
		BASES = new string[1];
		BASES[0] = "0.0";
		return 0;
		}
	delete selos_b;
	}

/**
 *
 */
void PDFNEW::dados_caixa (int *r, int *x)
	{
	string SQL, AUX;
	char *sql, *aux;
	int i,it;
	float valor;
	BANCOPG *caixa;
	vector<vector<string> >::iterator ir;
	vector<string> linha;

	caixa = new BANCOPG(CONF_FILE);
	SQL.clear();
	SQL = "select servicos.codigo, servicos.descricao, sum(entrada.total-(entrada.funjecc10+entrada.issqn)), sum(entrada.desconto), sum(entrada.total_liq-(entrada.funjecc10+entrada.issqn)) from caixa.entrada inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv inner join caixa.lancamentos on entrada.rec=lancamentos.rec and entrada.e_s=lancamentos.e_s and entrada.data=lancamentos.data where lancamentos.data_qt >= '"+this->datas[0]+"' and lancamentos.data_qt <= '"+this->datas[1]+"' and (entrada.cod_serv>=14 and entrada.cod_serv<=21 or entrada.cod_serv=38) group by servicos.codigo, servicos.descricao order by servicos.codigo";
	//cout << SQL << endl;
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	caixa->executar(sql);
	delete sql;
	if (caixa->query_result != 3)
		{
		caixa->resultado();
		*x = *x - 15;
		*r = *r + 1;
		this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
	  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
		HPDF_Page_BeginText (this->Pagina);
		HPDF_Page_SetTextLeading (this->Pagina, 10);
		aux = new char[64];
		strcpy(aux,"Serviços passados no Caixa no Período");
		HPDF_Page_TextRect (this->Pagina,25, *x, 300, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
		HPDF_Page_EndText (this->Pagina);
		delete aux;
		*x = *x - 15;
		*r = *r + 1;
		for (i=0, ir=caixa->resultados.begin(); i < caixa->registros, ir < caixa->resultados.end();i++,ir++)
			{
			linha = *ir;
			this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
	  		HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux = new char[linha.at(0).length()+1];
			strcpy(aux,linha.at(0).c_str());
			HPDF_Page_TextRect (this->Pagina,25, *x, 60, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			aux = new char[linha.at(1).length()+1];
			strcpy(aux,linha.at(1).c_str());
			HPDF_Page_TextRect (this->Pagina,60, *x, 200, 15, converter(aux,1), HPDF_TALIGN_LEFT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			AUX.clear();
			AUX = linha.at(2);
			it = AUX.find(".");
			if (it != string::npos)
				{
				AUX.replace(it,1,".");
				}
			valor = atof(AUX.c_str());
			aux = new char[32];
			sprintf(aux,"%0.3f",valor);
			aux[strlen(aux)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux,0);
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,200, *x, 300, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			AUX.clear();
			AUX = linha.at(3);
			it = AUX.find(".");
			if (it != string::npos)
				{
				AUX.replace(it,1,".");
				}
			valor = atof(AUX.c_str());
			aux = new char[32];
			sprintf(aux,"%0.3f",valor);
			aux[strlen(aux)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux,0);
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,300, *x, 400, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			HPDF_Page_BeginText (this->Pagina);
			HPDF_Page_SetTextLeading (this->Pagina, 10);
			AUX.clear();
			AUX = linha.at(4);
			it = AUX.find(".");
			if (it != string::npos)
				{
				AUX.replace(it,1,".");
				}
			valor = atof(AUX.c_str());
			aux = new char[32];
			sprintf(aux,"%0.3f",valor);
			aux[strlen(aux)-1] = '\0';
			AUX.clear();
			AUX = casa_milhar(aux,0);
			strcpy(aux,AUX.c_str());
			HPDF_Page_TextRect (this->Pagina,400, *x, 500, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
			HPDF_Page_EndText (this->Pagina);
			delete aux;
			*x = *x - 15;
			*r = *r + 1;
			if (*r >= 48)
				{
				this->set_rodape ();
				*r = 1;
				*x = 765;
				this->pag++;
				this->Pagina = HPDF_AddPage (this->PDF_doc);
				HPDF_Page_SetSize(this->Pagina,HPDF_PAGE_SIZE_A4,HPDF_PAGE_PORTRAIT);

			  	this->Altura = HPDF_Page_GetHeight (this->Pagina);
			  	this->Largura = HPDF_Page_GetWidth (this->Pagina);

				this->set_cabecalho();
				//Setando fonte padrão
				this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Roman", "WinAnsiEncoding");
			  	HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
				}
			}
		}
	else
		{
		cout << caixa->mensagem << endl;
		}
	SQL.clear();
	SQL = "select sum(entrada.total-(entrada.funjecc10+entrada.issqn)), sum(entrada.desconto), sum(entrada.total_liq-(entrada.funjecc10+entrada.issqn)) from caixa.entrada inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv inner join caixa.lancamentos on entrada.rec=lancamentos.rec and entrada.e_s=lancamentos.e_s and entrada.data=lancamentos.data where lancamentos.data_qt >= '"+this->datas[0]+"' and lancamentos.data_qt <= '"+this->datas[1]+"' and (entrada.cod_serv>=14 and entrada.cod_serv<=21 or entrada.cod_serv=38)";
	//cout << SQL << endl;
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	caixa->executar(sql);
	delete sql;
	if (caixa->query_result != 3)
		{
		caixa->resultado();
		ir = caixa->resultados.begin();
		linha = *ir;
		this->Font_Definida = HPDF_GetFont (this->PDF_doc, "Times-Bold", "WinAnsiEncoding");
  		HPDF_Page_SetFontAndSize (this->Pagina, this->Font_Definida, 12);
		HPDF_Page_BeginText (this->Pagina);
		HPDF_Page_SetTextLeading (this->Pagina, 10);
		AUX.clear();
		AUX = linha.at(0);
		it = AUX.find(".");
		if (it != string::npos)
			{
			AUX.replace(it,1,".");
			}
		valor = atof(AUX.c_str());
		aux = new char[32];
		sprintf(aux,"%0.3f",valor);
		aux[strlen(aux)-1] = '\0';
		AUX.clear();
		AUX = casa_milhar(aux,0);
		strcpy(aux,AUX.c_str());
		HPDF_Page_TextRect (this->Pagina,200, *x, 300, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
		HPDF_Page_EndText (this->Pagina);
		delete aux;
		HPDF_Page_BeginText (this->Pagina);
		HPDF_Page_SetTextLeading (this->Pagina, 10);
		AUX.clear();
		AUX = linha.at(1);
		it = AUX.find(".");
		if (it != string::npos)
			{
			AUX.replace(it,1,".");
			}
		valor = atof(AUX.c_str());
		aux = new char[32];
		sprintf(aux,"%0.3f",valor);
		aux[strlen(aux)-1] = '\0';
		AUX.clear();
		AUX = casa_milhar(aux,0);
		strcpy(aux,AUX.c_str());
		HPDF_Page_TextRect (this->Pagina,300, *x, 400, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
		HPDF_Page_EndText (this->Pagina);
		delete aux;
		HPDF_Page_BeginText (this->Pagina);
		HPDF_Page_SetTextLeading (this->Pagina, 10);
		AUX.clear();
		AUX = linha.at(2);
		it = AUX.find(".");
		if (it != string::npos)
			{
			AUX.replace(it,1,".");
			}
		valor = atof(AUX.c_str());
		aux = new char[32];
		sprintf(aux,"%0.3f",valor);
		aux[strlen(aux)-1] = '\0';
		AUX.clear();
		AUX = casa_milhar(aux,0);
		strcpy(aux,AUX.c_str());
		HPDF_Page_TextRect (this->Pagina,400, *x, 500, 15, converter(aux,1), HPDF_TALIGN_RIGHT, NULL);
		HPDF_Page_EndText (this->Pagina);
		delete aux;
		*x = *x - 15;
		*r = *r + 1;
		}
	else
		{
		cout << caixa->mensagem << endl;
		}
	delete caixa;
	}
